class OdeskJobnotifier::CommandLineTool
Handles invoking gem with binary.
Public Class Methods
new(config_dir = Dir.home)
click to toggle source
# File lib/odesk_jobnotifier/command_line_tool.rb, line 6 def initialize(config_dir = Dir.home) file_path = "#{config_dir}/.odesk-jobnotifier.yml" if File.exist?(file_path) config = YAML.load_file(file_path) config['queries'] = convert_query_string_params(config['queries']) @config = convert_params(config) else abort("Configuration file #{file_path} is missing.") end end
Public Instance Methods
run()
click to toggle source
# File lib/odesk_jobnotifier/command_line_tool.rb, line 17 def run OdeskJobnotifier.new(@config).run end
Private Instance Methods
convert_params(params)
click to toggle source
# File lib/odesk_jobnotifier/command_line_tool.rb, line 35 def convert_params(params) params.each_with_object({}) do |(k, v), memo| memo[k.to_sym] = if v.instance_of?(Hash) convert_params(v) elsif v.instance_of?(Array) memo[k.to_sym] = v.map do |el| el.instance_of?(Hash) ? convert_params(el) : el end else memo[k.to_sym] = v end end end
convert_query_string_params(queries)
click to toggle source
# File lib/odesk_jobnotifier/command_line_tool.rb, line 23 def convert_query_string_params(queries) queries.map do |q| if q.instance_of?(String) CGI.parse(URI(q).query).each_with_object({}) do |(k, v), memo| memo[k] = v.first end else q end end end