Class: Shufu::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/shufu/command.rb

Instance Method Summary collapse

Constructor Details

#initialize(schema) ⇒ Command

Returns a new instance of Command.

Parameters:

  • schema (Hash)


6
7
8
# File 'lib/shufu/command.rb', line 6

def initialize(schema)
  @schema = schema
end

Instance Method Details

#arguments(schema, values, args) ⇒ Object

Parameters:

  • schema (Hash)
  • values (Hash)


22
23
24
25
26
27
28
29
30
31
32
# File 'lib/shufu/command.rb', line 22

def arguments(schema, values, args)
  schema.each do |k, v|
    if v.is_a?(Hash)
      args = arguments(v, values, args).prepend(k)
    else
      args << Argument.new(name: k, type: v).to_s(values[k]) if values[k]
    end
  end

  args
end

#to_s(values) ⇒ String

Parameters:

  • values (Hash)

Returns:

  • (String)


14
15
16
# File 'lib/shufu/command.rb', line 14

def to_s(values)
  arguments(@schema, values, []).join(" ")
end