Method: Svgcode::SVG::Command#initialize

Defined in:
lib/svgcode/svg/command.rb

#initialize(str_or_opts) ⇒ Command

Returns a new instance of Command.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/svgcode/svg/command.rb', line 15

def initialize(str_or_opts)
  if str_or_opts.is_a?(Hash)
    @name = str_or_opts[:name]
    @absolute = !!str_or_opts[:absolute]
    @points = str_or_opts[:points]
  else
    str = str_or_opts
    @name = NAMES[str[0].to_s.downcase]

    @absolute =
    if @name == :close
      true
    else
      !!str[0].match(/[A-Z]/)
    end

    if @name != :close && str.length > 1
      @points = Point.parse(str[1..(str.length - 1)])
    end
  end

  @points = [] if @points.nil?
end