Class: Raph::Parser::AssignmentParser

Inherits:
BaseParser
  • Object
show all
Defined in:
lib/raph/parser/assignment_parser.rb

Overview

Considers option as assignment if and only if it has an assignment character (=) between option key and option value.

Assumes that each option doesn't have spaces.

Example of assignments: 'h=one' '-assg=two' '--config=my-file'

Example of non-assignments: '-h' '-h=' 'h=' '=' '--config='

Instance Method Summary collapse

Methods inherited from BaseParser

#id

Instance Method Details

#assignment?(option) ⇒ Boolean


31
32
33
34
35
# File 'lib/raph/parser/assignment_parser.rb', line 31

def assignment?(option)
  option.count('=') == 1 &&
    !option.start_with?('=') &&
    !option.end_with?('=')
end

#parse(args) ⇒ Object


18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/raph/parser/assignment_parser.rb', line 18

def parse(args)
  assgs = {}
  args.each do |a|
    if assignment? a
      kv = a.split('=')
      k = to_underscored_sym(kv.first)
      v = kv.last
      assgs[k] = v
    end
  end
  assgs
end