Class: Savage::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/savage/parser.rb

Constant Summary collapse

DIRECTIONS =
{
  :m => {:class => Directions::MoveTo,
         :args => 2},
  :l => {:class => Directions::LineTo,
         :args => 2},
  :h => {:class => Directions::HorizontalTo,
         :args => 1},
  :v => {:class => Directions::VerticalTo,
         :args => 1},
  :c => {:class => Directions::CubicCurveTo,
         :args => 6},
  :s => {:class => Directions::CubicCurveTo,
         :args => 4},
  :q => {:class => Directions::QuadraticCurveTo,
         :args => 4},
  :t => {:class => Directions::QuadraticCurveTo,
         :args => 2},
  :a => {:class => Directions::ArcTo,
         :args => 7}
}

Class Method Summary collapse

Class Method Details

.parse(parsable) ⇒ Object

Raises:

  • (TypeError)


25
26
27
28
29
30
31
32
33
34
35
# File 'lib/savage/parser.rb', line 25

def parse(parsable)
  raise TypeError if parsable.class != String
  subpaths = extract_subpaths parsable
  raise TypeError if (subpaths.empty?)
  path = Path.new
  path.subpaths = []
  subpaths.each_with_index do |subpath, i|
    path.subpaths << parse_subpath(subpath, i == 0)
  end
  path
end