Class: RelatonBib::Image
Instance Attribute Summary collapse
- #alt ⇒ String readonly
- #filename ⇒ String readonly
- #height ⇒ String readonly
- #id ⇒ String readonly
- #longdesc ⇒ String readonly
- #mimetype ⇒ String readonly
- #src ⇒ String readonly
- #title ⇒ String readonly
- #width ⇒ String readonly
Instance Method Summary collapse
-
#initialize(id:, 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(id:, src:, mimetype:, **args) ⇒ Image
Initializes a new Image object.
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/relaton_bib/image.rb', line 20 def initialize(id:, src:, mimetype:, **args) @id = id @src = src @mimetype = mimetype @filename = args[:filename] @width = args[:width] @height = args[:height] @alt = args[:alt] @title = args[:title] @longdesc = args[:longdesc] end |
Instance Attribute Details
#alt ⇒ String (readonly)
4 5 6 |
# File 'lib/relaton_bib/image.rb', line 4 def alt @alt end |
#filename ⇒ String (readonly)
4 5 6 |
# File 'lib/relaton_bib/image.rb', line 4 def filename @filename end |
#height ⇒ String (readonly)
4 5 6 |
# File 'lib/relaton_bib/image.rb', line 4 def height @height end |
#id ⇒ String (readonly)
4 5 6 |
# File 'lib/relaton_bib/image.rb', line 4 def id @id end |
#longdesc ⇒ String (readonly)
4 5 6 |
# File 'lib/relaton_bib/image.rb', line 4 def longdesc @longdesc end |
#mimetype ⇒ String (readonly)
4 5 6 |
# File 'lib/relaton_bib/image.rb', line 4 def mimetype @mimetype end |
#src ⇒ String (readonly)
4 5 6 |
# File 'lib/relaton_bib/image.rb', line 4 def src @src end |
#title ⇒ String (readonly)
4 5 6 |
# File 'lib/relaton_bib/image.rb', line 4 def title @title end |
#width ⇒ String (readonly)
4 5 6 |
# File 'lib/relaton_bib/image.rb', line 4 def width @width end |
Instance Method Details
#to_asciibib(prefix = "") ⇒ String
Converts the image object to AsciiBib format.
76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/relaton_bib/image.rb', line 76 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 += "#{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.
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/relaton_bib/image.rb', line 58 def to_hash # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity hash = { "image" => { "id" => id, "src" => src, "mimetype" => mimetype } } 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.
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/relaton_bib/image.rb', line 39 def to_xml(builder) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength builder.image do builder.parent[:id] = 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 |