Class: RelatonBib::Image

Inherits:
Object show all
Defined in:
lib/relaton_bib/image.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, src:, mimetype:, **args) ⇒ Image

Initializes a new Image object.

Parameters:

  • id (String)

    the ID of the image

  • src (String)

    the source URL of the image

  • mimetype (String)

    the MIME type of the image

  • args (Hash)

    additional arguments

Options Hash (**args):

  • :filename (String)

    the filename of the image

  • :width (String)

    the width of the image

  • :height (String)

    the height of the image

  • :alt (String)

    the alternative text for the image

  • :title (String)

    the title of the image

  • :longdesc (String)

    the long description of the image



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

#altString (readonly)

Returns:

  • (String)


4
5
6
# File 'lib/relaton_bib/image.rb', line 4

def alt
  @alt
end

#filenameString (readonly)

Returns:

  • (String)


4
5
6
# File 'lib/relaton_bib/image.rb', line 4

def filename
  @filename
end

#heightString (readonly)

Returns:

  • (String)


4
5
6
# File 'lib/relaton_bib/image.rb', line 4

def height
  @height
end

#idString (readonly)

Returns:

  • (String)


4
5
6
# File 'lib/relaton_bib/image.rb', line 4

def id
  @id
end

#longdescString (readonly)

Returns:

  • (String)


4
5
6
# File 'lib/relaton_bib/image.rb', line 4

def longdesc
  @longdesc
end

#mimetypeString (readonly)

Returns:

  • (String)


4
5
6
# File 'lib/relaton_bib/image.rb', line 4

def mimetype
  @mimetype
end

#srcString (readonly)

Returns:

  • (String)


4
5
6
# File 'lib/relaton_bib/image.rb', line 4

def src
  @src
end

#titleString (readonly)

Returns:

  • (String)


4
5
6
# File 'lib/relaton_bib/image.rb', line 4

def title
  @title
end

#widthString (readonly)

Returns:

  • (String)


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.

Parameters:

  • prefix (String) (defaults to: "")

    The prefix to be added to the AsciiBib output.

Returns:

  • (String)

    The image object converted 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_hashHash

Converts the Image object to a hash representation.

Returns:

  • (Hash)

    The hash representation of the Image object.



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.

Parameters:

  • builder (Nokogiri::XML::Builder)

    The XML builder object.



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