Class: Sunniesnow::Tools::SvgPath::Command
- Inherits:
-
Object
- Object
- Sunniesnow::Tools::SvgPath::Command
- Defined in:
- lib/sscharter/tools/svg_path.rb
Instance Method Summary collapse
-
#initialize(name, parameters, follow_up = name) ⇒ Command
constructor
A new instance of Command.
- #parse(path, tokens) ⇒ void
Constructor Details
#initialize(name, parameters, follow_up = name) ⇒ Command
Returns a new instance of Command.
318 319 320 321 322 |
# File 'lib/sscharter/tools/svg_path.rb', line 318 def initialize name, parameters, follow_up = name @name = name @parameters = parameters @follow_up = follow_up end |
Instance Method Details
#parse(path, tokens) ⇒ void
This method returns an undefined value.
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 |
# File 'lib/sscharter/tools/svg_path.rb', line 327 def parse path, tokens relative = (?a..?z).include? tokens.shift name = @name.to_sym begin arguments = @parameters.map do |parameter| case parameter when :point point = Vector2D.new tokens.shift.to_f, tokens.shift.to_f point += path.current if relative point when :point_x x = tokens.shift.to_f Vector2D.new relative ? path.current.x + x : x, path.current.y when :point_y y = tokens.shift.to_f Vector2D.new path.current.x, relative ? path.current.y + y : y when :vector Vector2D.new tokens.shift.to_f, tokens.shift.to_f when :number tokens.shift.to_f when :boolean raise "Invalid boolean: #{tokens.first}" unless %w[0 1].include? tokens.first tokens.shift == ?1 end end path.public_send name, *arguments name = @follow_up.to_sym end until tokens.empty? || tokens.first =~ /[a-zA-Z]/ end |