Class: SvgSprite::SVG

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filepath, optimize:, stroke:, fill:) ⇒ SVG

Returns a new instance of SVG.



7
8
9
10
11
12
# File 'lib/svg_sprite/svg.rb', line 7

def initialize(filepath, optimize:, stroke:, fill:)
  @filepath = filepath
  @optimize = optimize
  @stroke = stroke
  @fill = fill
end

Instance Attribute Details

#filepathObject (readonly)

Returns the value of attribute filepath.



5
6
7
# File 'lib/svg_sprite/svg.rb', line 5

def filepath
  @filepath
end

#fillObject (readonly)

Returns the value of attribute fill.



5
6
7
# File 'lib/svg_sprite/svg.rb', line 5

def fill
  @fill
end

#optimizeObject (readonly)

Returns the value of attribute optimize.



5
6
7
# File 'lib/svg_sprite/svg.rb', line 5

def optimize
  @optimize
end

#strokeObject (readonly)

Returns the value of attribute stroke.



5
6
7
# File 'lib/svg_sprite/svg.rb', line 5

def stroke
  @stroke
end

Instance Method Details

#heightObject



28
29
30
# File 'lib/svg_sprite/svg.rb', line 28

def height
  symbol[:height]
end

#idObject



32
33
34
# File 'lib/svg_sprite/svg.rb', line 32

def id
  File.basename(filepath, ".*")
end

#symbolObject



14
15
16
17
18
19
20
21
22
# File 'lib/svg_sprite/svg.rb', line 14

def symbol
  @symbol ||= xml.css("svg").first.clone.tap do |node|
    node.name = "symbol"
    node.set_attribute :id, id

    process_stroke(node)
    process_fill(node)
  end
end

#widthObject



24
25
26
# File 'lib/svg_sprite/svg.rb', line 24

def width
  symbol[:width]
end