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(src:, mimetype:, **args) ⇒ Image

Initializes a new Image object.

Parameters:

  • src (String)

    the source URL of the image

  • mimetype (String)

    the MIME type of the image

  • args (Hash)

    additional arguments

  • id (Hash)

    a customizable set of options

Options Hash (**args):

  • :filename (String, nil)

    the filename of the image

  • :width (String, nil)

    the width of the image

  • :height (String, nil)

    the height of the image

  • :alt (String, nil)

    the alternative text for the image

  • :title (String, nil)

    the title of the image

  • :longdesc (String, nil)

    the long description of the image



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

#altString?

Returns:

  • (String, nil)


7
8
9
# File 'lib/relaton_bib/image.rb', line 7

def alt
  @alt
end

#filenameString?

Returns:

  • (String, nil)


7
8
9
# File 'lib/relaton_bib/image.rb', line 7

def filename
  @filename
end

#heightString?

Returns:

  • (String, nil)


7
8
9
# File 'lib/relaton_bib/image.rb', line 7

def height
  @height
end

#idString?

Returns:

  • (String, nil)


7
8
9
# File 'lib/relaton_bib/image.rb', line 7

def id
  @id
end

#longdescString?

Returns:

  • (String, nil)


7
8
9
# File 'lib/relaton_bib/image.rb', line 7

def longdesc
  @longdesc
end

#mimetypeString

Returns:

  • (String)


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

def mimetype
  @mimetype
end

#srcString

Returns:

  • (String)


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

def src
  @src
end

#titleString?

Returns:

  • (String, nil)


7
8
9
# File 'lib/relaton_bib/image.rb', line 7

def title
  @title
end

#widthString?

Returns:

  • (String, nil)


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.

Parameters:

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

    The prefix to be added to the AsciiBib output.

Returns:

  • (String)

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

Converts the Image object to a hash representation.

Returns:

  • (Hash)

    The hash representation of the Image object.



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.

Parameters:

  • builder (Nokogiri::XML::Builder)

    The XML builder object.



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