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

Returns:

  • (Boolean)


26
27
28
29
30
# File 'lib/raph/parser/assignment_parser.rb', line 26

def assignment?(option)
  option.include?('=')\
  && !option.start_with?('=')\
  && !option.end_with?('=')
end

#parse(args) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/raph/parser/assignment_parser.rb', line 18

def parse(args)
  assgs = []
  args.each do |a|
    assgs << a if assignment? a
  end
  assgs
end