class Antex::SVGBox

Loads and manages measures for SVG pictures.

Public Instance Methods

load(filepath) click to toggle source

Loads an SVG file and extracts the measures of its viewBox.

@param filepath [String] the path of the SVG file to load @return [SVGBox] returns self after loading

# 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