class Command
Public Class Methods
new(name, args)
click to toggle source
# File lib/YASP/command.rb, line 3 def initialize(name, args) @label = name if (args.last.is_a?(Hash)) @args = args[0...-1] @opts = args.last else @args = args @opts = {} end @children = [] end
Public Instance Methods
<<(child)
click to toggle source
# File lib/YASP/command.rb, line 17 def <<(child)#TODO deferral mixin #TODO what the hell does 'deferral mixin' mean? why was I so bad at coments? @children << child end
argstring()
click to toggle source
# File lib/YASP/command.rb, line 30 def argstring @args.map(&:inspect).join(", ").chomp(", ") end
indent(depth)
click to toggle source
# File lib/YASP/command.rb, line 38 def indent(depth) " "*depth end
label()
click to toggle source
# File lib/YASP/command.rb, line 26 def label @label end
opts()
click to toggle source
# File lib/YASP/command.rb, line 22 def opts @opts end
optstring()
click to toggle source
# File lib/YASP/command.rb, line 34 def optstring @opts.map { |key, value| "#{key}=#{value.inspect}"}.join(", ").chomp(", ") end
parse_arguments()
click to toggle source
# File lib/YASP/command.rb, line 42 def parse_arguments if @opts.empty? argstring elsif @args.empty? optstring else "#{argstring}, #{optstring}" end end
parse_children(depth)
click to toggle source
# File lib/YASP/command.rb, line 52 def parse_children(depth) @children.map{ |c| c.to_scad(depth) }.join() end
parse_nested_children(depth)
click to toggle source
# File lib/YASP/command.rb, line 56 def parse_nested_children(depth) unless @children.empty? "{\n#{parse_children(depth)}#{indent(depth-1)}}" end end
to_scad(depth)
click to toggle source
# File lib/YASP/command.rb, line 62 def to_scad(depth) if label "#{indent(depth)}#{label}(#{parse_arguments})#{parse_nested_children(depth+1)};\n" else parse_children(depth) end end