Skip to content

Commit

Permalink
allow images without ID
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew2net committed Jul 23, 2024
1 parent abb1eac commit e5b4f23
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
37 changes: 18 additions & 19 deletions lib/relaton_bib/image.rb
Original file line number Diff line number Diff line change
@@ -1,32 +1,29 @@
module RelatonBib
class Image
# @return [String]
attr_reader :id, :src, :mimetype, :filename, :width, :height, :alt, :title, :longdesc
attr_accessor :src, :mimetype

# @return [String, nil]
attr_accessor :id, :filename, :width, :height, :alt, :title, :longdesc

#
# Initializes a new Image object.
#
# @param id [String] the ID of the image
# @param src [String] the source URL of the image
# @param mimetype [String] the MIME type of the image
# @param args [Hash] additional arguments
# @option args [String] :filename the filename of the image
# @option args [String] :width the width of the image
# @option args [String] :height the height of the image
# @option args [String] :alt the alternative text for the image
# @option args [String] :title the title of the image
# @option args [String] :longdesc the long description of the image
# @option id [String, nil] the ID of the image
# @option args [String, nil] :filename the filename of the image
# @option args [String, nil] :width the width of the image
# @option args [String, nil] :height the height of the image
# @option args [String, nil] :alt the alternative text for the image
# @option args [String, nil] :title the title of the image
# @option args [String, nil] :longdesc the long description of the image
#
def initialize(id:, src:, mimetype:, **args)
@id = id
def initialize(src:, mimetype:, **args)
@src = src
@mimetype = mimetype
@filename = args[:filename]
@width = args[:width]
@height = args[:height]
@alt = args[:alt]
@title = args[:title]
@longdesc = args[:longdesc]
args.each { |k, v| send "#{k}=", v }
end

def ==(other)
Expand All @@ -44,7 +41,7 @@ def ==(other)
#
def to_xml(builder) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength
builder.image do
builder.parent[:id] = id
builder.parent[:id] = id if id
builder.parent[:src] = src
builder.parent[:mimetype] = mimetype
builder.parent[:filename] = filename if filename
Expand All @@ -62,7 +59,8 @@ def to_xml(builder) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexi
# @return [Hash] The hash representation of the Image object.
#
def to_hash # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity
hash = { "image" => { "id" => id, "src" => src, "mimetype" => mimetype } }
hash = { "image" => { "src" => src, "mimetype" => mimetype } }
hash["image"]["id"] = id if id
hash["image"]["filename"] = filename if filename
hash["image"]["width"] = width if width
hash["image"]["height"] = height if height
Expand All @@ -81,7 +79,8 @@ def to_hash # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity
#
def to_asciibib(prefix = "") # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity,Metrics/MethodLength
pref = prefix.empty? ? "image." : "#{prefix}.image."
out = "#{pref}id:: #{id}\n"
out = ""
out += "#{pref}id:: #{id}\n" if id
out += "#{pref}src:: #{src}\n"
out += "#{pref}mimetype:: #{mimetype}\n"
out += "#{pref}filename:: #{filename}\n" if filename
Expand Down
2 changes: 1 addition & 1 deletion lib/relaton_bib/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module RelatonBib
VERSION = "1.19.2".freeze
VERSION = "1.19.3".freeze
end

0 comments on commit e5b4f23

Please sign in to comment.