Class: Slnky::Command::Processor
- Inherits:
-
Object
- Object
- Slnky::Command::Processor
- Defined in:
- lib/slnky/command.rb
Instance Attribute Summary collapse
-
#banner ⇒ Object
readonly
Returns the value of attribute banner.
-
#doc ⇒ Object
readonly
Returns the value of attribute doc.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(name, banner, doc) ⇒ Processor
constructor
A new instance of Processor.
- #process(args) ⇒ Object
- #usage ⇒ Object
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, , doc) @name = name.to_s = @doc = doc =~ /^Usage/ ? doc : "Usage: #{doc}" end |
Instance Attribute Details
#banner ⇒ Object (readonly)
Returns the value of attribute banner.
74 75 76 |
# File 'lib/slnky/command.rb', line 74 def end |
#doc ⇒ Object (readonly)
Returns the value of attribute doc.
75 76 77 |
# File 'lib/slnky/command.rb', line 75 def doc @doc end |
#name ⇒ Object (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 |
#usage ⇒ Object
83 84 85 |
# File 'lib/slnky/command.rb', line 83 def usage doc.lines.first.chomp end |