Class: Antex::SVGBox

Inherits:
Measurable show all
Defined in:
lib/antex/svg_box.rb

Overview

Loads and manages measures for SVG pictures.

Instance Attribute Summary

Attributes inherited from Measurable

#default_unit, #measures

Instance Method Summary collapse

Methods inherited from Measurable

#initialize

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.

Parameters:

  • filepath (String)

    the path of the SVG file to load

Returns:

  • (SVGBox)

    returns self after loading



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