Class: RelatonBib::Image
Instance Attribute Summary collapse
- #alt ⇒ String?
- #filename ⇒ String?
- #height ⇒ String?
- #id ⇒ String?
- #longdesc ⇒ String?
- #mimetype ⇒ String
- #src ⇒ String
- #title ⇒ String?
- #width ⇒ String?
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(src:, mimetype:, **args) ⇒ Image
constructor
Initializes a new Image object.
-
#to_asciibib(prefix = "") ⇒ String
Converts the image object to AsciiBib format.
-
#to_hash ⇒ Hash
Converts the Image object to a hash representation.
-
#to_xml(builder) ⇒ void
Converts the image object to XML format.
Constructor Details
#initialize(src:, mimetype:, **args) ⇒ Image
Initializes a new Image object.
23 24 25 26 27 |
# File 'lib/relaton_bib/image.rb', line 23 def initialize(src:, mimetype:, **args) @src = src @mimetype = mimetype args.each { |k, v| send "#{k}=", v } end |
Instance Attribute Details
#alt ⇒ String?
7 8 9 |
# File 'lib/relaton_bib/image.rb', line 7 def alt @alt end |
#filename ⇒ String?
7 8 9 |
# File 'lib/relaton_bib/image.rb', line 7 def filename @filename end |
#height ⇒ String?
7 8 9 |
# File 'lib/relaton_bib/image.rb', line 7 def height @height end |
#id ⇒ String?
7 8 9 |
# File 'lib/relaton_bib/image.rb', line 7 def id @id end |
#longdesc ⇒ String?
7 8 9 |
# File 'lib/relaton_bib/image.rb', line 7 def longdesc @longdesc end |
#mimetype ⇒ String
4 5 6 |
# File 'lib/relaton_bib/image.rb', line 4 def mimetype @mimetype end |
#src ⇒ String
4 5 6 |
# File 'lib/relaton_bib/image.rb', line 4 def src @src end |
#title ⇒ String?
7 8 9 |
# File 'lib/relaton_bib/image.rb', line 7 def title @title end |
#width ⇒ String?
7 8 9 |
# File 'lib/relaton_bib/image.rb', line 7 def width @width end |
Instance Method Details
#==(other) ⇒ Object
29 30 31 32 33 |
# File 'lib/relaton_bib/image.rb', line 29 def ==(other) other.is_a?(Image) && id == other.id && src == other.src && mimetype == other.mimetype && filename == other.filename && width == other.width && height == other.height && alt == other.alt && title == other.title && longdesc == other.longdesc end |
#to_asciibib(prefix = "") ⇒ String
Converts the image object to AsciiBib format.
80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/relaton_bib/image.rb', line 80 def to_asciibib(prefix = "") # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity,Metrics/MethodLength pref = prefix.empty? ? "image." : "#{prefix}.image." 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 out += "#{pref}width:: #{width}\n" if width out += "#{pref}height:: #{height}\n" if height out += "#{pref}alt:: #{alt}\n" if alt out += "#{pref}title:: #{title}\n" if title out += "#{pref}longdesc:: #{longdesc}\n" if longdesc out end |
#to_hash ⇒ Hash
Converts the Image object to a hash representation.
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/relaton_bib/image.rb', line 61 def to_hash # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity 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 hash["image"]["alt"] = alt if alt hash["image"]["title"] = title if title hash["image"]["longdesc"] = longdesc if longdesc hash end |
#to_xml(builder) ⇒ void
This method returns an undefined value.
Converts the image object to XML format.
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/relaton_bib/image.rb', line 42 def to_xml(builder) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength builder.image do builder.parent[:id] = id if id builder.parent[:src] = src builder.parent[:mimetype] = mimetype builder.parent[:filename] = filename if filename builder.parent[:width] = width if width builder.parent[:height] = height if height builder.parent[:alt] = alt if alt builder.parent[:title] = title if title builder.parent[:longdesc] = longdesc if longdesc end end |