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.



5
6
7
# File 'lib/lab42/options/parser.rb', line 5

def data
  @data
end

#defaultsObject

Returns the value of attribute defaults.



5
6
7
# File 'lib/lab42/options/parser.rb', line 5

def defaults
  @defaults
end

#kwdsObject

Returns the value of attribute kwds.



5
6
7
# File 'lib/lab42/options/parser.rb', line 5

def kwds
  @kwds
end

#positionalsObject

Returns the value of attribute positionals.



5
6
7
# File 'lib/lab42/options/parser.rb', line 5

def positionals
  @positionals
end

#yaml_fileObject

Returns the value of attribute yaml_file.



5
6
7
# File 'lib/lab42/options/parser.rb', line 5

def yaml_file
  @yaml_file
end

Instance Method Details

#parse(options, args) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/lab42/options/parser.rb', line 6

def parse options, args
  self.yaml_file = options.yaml_file 
  self.data = {to_a: args}
  self.kwds = {}
  self.positionals = []
  parse_all args
  # read_yaml file might need the args parsed
  defaults = read_yaml_file
  data.merge kwds: OpenStruct.new(defaults.merge(kwds)), args: positionals
end