Class: PuppetTwitch::ParamParser

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet_twitch/param_parser.rb

Class Method Summary collapse

Class Method Details

.parse(param_strings) ⇒ Object

Takes an array of parameter strings and returns a hash of the parameters and their values where the keys are the parameter names as symbols.

Parameter strings can have the following formats:

'name=value'    -->    { :name => 'value' }
'name'          -->    { :name => true }


13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/puppet_twitch/param_parser.rb', line 13

def self.parse(param_strings)
  params = {}
  param_strings.each { |pair|
    key_value = pair.split('=')
    if key_value.size > 2 || pair[-1] == '='
      raise StandardError, "Invalid parameter format: #{pair}"
    else
      params[key_value[0].to_sym] = (key_value.size == 1) ? true : key_value[1]
    end
  }
  params
end