Class: Antex::SVGBox
- Inherits:
-
Measurable
- Object
- Measurable
- Antex::SVGBox
- Defined in:
- lib/antex/svg_box.rb
Overview
Loads and manages measures for SVG
pictures.
Instance Attribute Summary
Attributes inherited from Measurable
Instance Method Summary collapse
-
#load(filepath) ⇒ SVGBox
Loads an
SVG
file and extracts the measures of itsviewBox
.
Methods inherited from Measurable
Constructor Details
This class inherits a constructor from Antex::Measurable
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Antex::Measurable
Instance Method Details
#load(filepath) ⇒ SVGBox
Loads an SVG
file and extracts the measures of its viewBox
.
12 13 14 15 16 17 18 19 20 |
# File 'lib/antex/svg_box.rb', line 12 def load(filepath) svg_ast = Nokogiri::XML.parse File.read(filepath) view_box = svg_ast.css('svg').attribute('viewBox') magnitudes = view_box.to_s.split.map(&:to_f) @measures = %i[ox oy dx dy].zip(magnitudes).to_h @measures[:px] ||= 1.0 @default_unit = :px self end |