Class: Lab42::Options::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/lab42/options/parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#dataObject

Returns the value of attribute data.



9
10
11
# File 'lib/lab42/options/parser.rb', line 9

def data
  @data
end

#defaultsObject

Returns the value of attribute defaults.



9
10
11
# File 'lib/lab42/options/parser.rb', line 9

def defaults
  @defaults
end

#kwdsObject

Returns the value of attribute kwds.



9
10
11
# File 'lib/lab42/options/parser.rb', line 9

def kwds
  @kwds
end

#positionalsObject

Returns the value of attribute positionals.



9
10
11
# File 'lib/lab42/options/parser.rb', line 9

def positionals
  @positionals
end

#yaml_fileObject

Returns the value of attribute yaml_file.



9
10
11
# File 'lib/lab42/options/parser.rb', line 9

def yaml_file
  @yaml_file
end

Instance Method Details

#errorsObject



24
# File 'lib/lab42/options/parser.rb', line 24

def errors; @errors.dup end

#parse(option, args) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/lab42/options/parser.rb', line 11

def parse option, args
  self.yaml_file = option.yaml_file 
  self.data = {to_a: args}
  parse_all args
  # read_yaml file might need the args parsed
  defaults = read_yaml_file || option.defaults
  merged = defaults.merge kwds
  merged = extend_values merged
  result = data.merge kwds: OpenStruct.new( merged ), args: positionals
  check_for_errors option, args if option.strict_mode
  result
end