Class: Slnky::Command::Processor

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, banner, doc) ⇒ Processor

Returns a new instance of Processor.



77
78
79
80
81
# File 'lib/slnky/command.rb', line 77

def initialize(name, banner, doc)
  @name = name.to_s
  @banner = banner
  @doc = doc =~ /^Usage/ ? doc : "Usage: #{doc}"
end

Instance Attribute Details

Returns the value of attribute banner.



74
75
76
# File 'lib/slnky/command.rb', line 74

def banner
  @banner
end

#docObject (readonly)

Returns the value of attribute doc.



75
76
77
# File 'lib/slnky/command.rb', line 75

def doc
  @doc
end

#nameObject (readonly)

Returns the value of attribute name.



73
74
75
# File 'lib/slnky/command.rb', line 73

def name
  @name
end

Instance Method Details

#process(args) ⇒ Object



87
88
89
90
91
92
93
94
95
# File 'lib/slnky/command.rb', line 87

def process(args)
  opts = Docopt::docopt(@doc, argv: args)
  data = Slnky::Data.new
  opts.each do |key, value|
    k = key.gsub(/^--/, '').downcase
    data.send("#{k}=", value)
  end
  data
end

#usageObject



83
84
85
# File 'lib/slnky/command.rb', line 83

def usage
  doc.lines.first.chomp
end