Class: Dashdate::ArgParser

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

Instance Method Summary collapse

Instance Method Details

#parse(args) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/arg_parser.rb', line 5

def parse args
  args = args.split.drop(1) unless args.class == Array 
  opts = parse_arg_array(args)
  return {
    :widget => opts[:widget].to_sym,
    :values => parse_value_string(opts[:values]),
    :auth => opts[:auth]
  }
end

#parse_arg_array(args) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/arg_parser.rb', line 14

def parse_arg_array args
  Trollop::options(args) do 
    opt :widget, "The name of the widget to publish to", :required => true, :short => :w, :type => String
    opt :values, "The values to push to the widget.  Format is: key1=value1,key2=value2", :required => true, :type => String
    opt :auth, "Your auth token.  Should match whats in config.ru.", :type => String
  end
end

#parse_value_string(string) ⇒ Object



21
22
23
24
25
26
# File 'lib/arg_parser.rb', line 21

def parse_value_string string
  string.split(',').each_with_object({}) do |key_equals_value, hash|
    key_value_pair = key_equals_value.split('=')
    hash[key_value_pair.first.to_sym] = key_value_pair.last
  end
end