Class: Gradient::SVG
- Inherits:
-
Object
- Object
- Gradient::SVG
- Defined in:
- lib/gradient/svg.rb
Constant Summary collapse
- SVGNS =
'http://www.w3.org/2000/svg'
Instance Attribute Summary collapse
-
#maps ⇒ Object
readonly
Returns the value of attribute maps.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ SVG
constructor
A new instance of SVG.
- #parse(buffer) ⇒ Object
Constructor Details
#initialize ⇒ SVG
Returns a new instance of SVG.
34 35 36 |
# File 'lib/gradient/svg.rb', line 34 def initialize @maps = {} end |
Instance Attribute Details
#maps ⇒ Object (readonly)
Returns the value of attribute maps.
10 11 12 |
# File 'lib/gradient/svg.rb', line 10 def maps @maps end |
Class Method Details
.open(file) ⇒ Object
28 29 30 |
# File 'lib/gradient/svg.rb', line 28 def open(file) read(file) end |
.parse(string_buffer) ⇒ Object
14 15 16 17 18 |
# File 'lib/gradient/svg.rb', line 14 def parse(string_buffer) new.tap do |parser| parser.parse(string_buffer) end.maps end |
.read(file) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/gradient/svg.rb', line 20 def read(file) new.tap do |parser| File.open(file, 'r') do |file| parser.parse(file.read) end end.maps end |
Instance Method Details
#parse(buffer) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/gradient/svg.rb', line 40 def parse(buffer) xml = Nokogiri::XML(buffer) ( xml.xpath('//linearGradient') + xml.xpath('//xmlns:linearGradient', 'xmlns' => SVGNS) ).each do |linear_gradient| unless (id = linear_gradient['id']) then raise SVGError, 'linearGradient has no id' end unless (map = parse_linear_gradient(linear_gradient)).points.empty? @maps[id] = map end end end |