Class: BasicBlock::Image

Inherits:
Object
  • Object
show all
Defined in:
lib/relaton_iec/basic_block/image.rb

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Image.

Parameters:

  • id (String)
  • src (String)
  • mimetype (String)
  • args (Hash)

Options Hash (**args):

  • :filename (String)


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/relaton_iec/basic_block/image.rb', line 10

def initialize(id:, src:, mimetype:, **args) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength
  @id = id
  @src = src
  @mimetype = mimetype
  @filename = args[:filename]
  if args[:width] && !args[:width].is_a?(Integer) && args[:width] != "auto"
    warn "[basic-block] WARNING: invalid image width attribute \"#{args[:width]}"
    warn "[basic-block] image width should be integer or \"auto\""
  end
  if args[:height] && !args[:height].is_a?(Integer) && args[:height] != "auto"
    warn "[basic-block] WARNING: invalid image height attribute \"#{args[:height]}"
    warn "[basic-block] image height should be integer or \"auto\""
  end
  @width = args[:width]
  @height = args[:height]
  @alt = args[:alt]
  @title = args[:title]
  @longdesc = args[:longdesc]
end

Instance Method Details

#to_xml(builder) ⇒ Object

Parameters:

  • (Nokogiri::XML::Builder)


31
32
33
34
35
36
37
38
39
# File 'lib/relaton_iec/basic_block/image.rb', line 31

def to_xml(builder) # rubocop:disable Metrics/CyclomaticComplexity
  img = builder.image id: @id, src: @src, mimetype: @mimetype
  img[:filename] = @filename if @filename
  img[:width] = @width if @width
  img[:height] = @height if @height
  img[:alt] = @alt if @alt
  img[:title] = @title if @title
  img[:longdesc] = @longdesc if @longdesc
end