Class: SimplyInlineSvg::Svg

Inherits:
Object
  • Object
show all
Defined in:
lib/simply_inline_svg/svg.rb

Instance Method Summary collapse

Constructor Details

#initialize(str_svg) ⇒ Svg

Returns a new instance of Svg.



6
7
8
9
# File 'lib/simply_inline_svg/svg.rb', line 6

def initialize(str_svg)
  @doc = XML::Parser.string(str_svg).parse
  @svg_attributes = @doc.root.attributes
end

Instance Method Details

#[](attr_name) ⇒ Object



15
16
17
# File 'lib/simply_inline_svg/svg.rb', line 15

def [](attr_name)
  @svg_attributes[attr_name.to_s]
end

#[]=(attr_name, attr_value) ⇒ Object



11
12
13
# File 'lib/simply_inline_svg/svg.rb', line 11

def []=(attr_name, attr_value)
  @svg_attributes[attr_name.to_s] = attr_value.to_s
end

#dupObject



19
20
21
# File 'lib/simply_inline_svg/svg.rb', line 19

def dup
  self.class.new(@doc.to_s)
end

#render(options = {}) ⇒ Object



27
28
29
30
31
32
# File 'lib/simply_inline_svg/svg.rb', line 27

def render(options = {})
  return self.to_s if options.empty?
  cloned_svg = self.dup
  options.each { |k, v| cloned_svg[k] = v }
  cloned_svg.to_s
end

#to_sObject



23
24
25
# File 'lib/simply_inline_svg/svg.rb', line 23

def to_s
  @doc.to_s
end