Class: Kangaru::ArgumentParser

Inherits:
Object
  • Object
show all
Defined in:
lib/kangaru/argument_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*tokens) ⇒ ArgumentParser

Returns a new instance of ArgumentParser.



7
8
9
# File 'lib/kangaru/argument_parser.rb', line 7

def initialize(*tokens)
  @tokens = tokens
end

Instance Attribute Details

#tokensObject (readonly)

Returns the value of attribute tokens.



5
6
7
# File 'lib/kangaru/argument_parser.rb', line 5

def tokens
  @tokens
end

Instance Method Details

#parseObject



11
12
13
14
15
16
17
18
# File 'lib/kangaru/argument_parser.rb', line 11

def parse
  grouped_argument_tokens.to_h do |tokens|
    key   = parse_key(tokens.shift || raise)
    value = parse_value(tokens)

    [key, value]
  end
end