module Dmail::Utils
Public Instance Methods
argument_present_or_direct(arg)
click to toggle source
# File lib/dmail/utils.rb, line 52 def argument_present_or_direct(arg) arg, value = if arg.include?('=') then arg.split('=') else [arg, true] end { arg => value } end
arguments()
click to toggle source
Parsing command-line arguments. Understands things like ‘-d’, ‘-c’, ‘-c 5’, ‘–count=5’, ‘–count 5’. Non-valued args like ‘-d’ get mapped to true to indicate presence.
# File lib/dmail/utils.rb, line 31 def arguments @args ||= {} unless @args.size > 0 ARGV.each_with_index do |arg, index| if arg.start_with?('-') if index + 1 < ARGV.size next_arg = ARGV[index + 1] if next_arg.start_with?('-') then @args.update(argument_present_or_direct(arg)) else @args.update(arg => next_arg) end else @args.update(argument_present_or_direct(arg)) end end end end @args end
get_params(keys, mappings)
click to toggle source
Converts arguments() to a pretty-named hash. Considers naming substitutes when doing so.
# File lib/dmail/utils.rb, line 15 def get_params(keys, mappings) params = {} [keys].flatten.each do |key| value = arguments[key.to_s] params[key] = value if value end mappings.each do |final_name, substitutes| value = substitutes.map { |s| arguments[s] }.find { |el| el } params[final_name] = value if value end params end
setup_pager!()
click to toggle source
I like this naming better :)
# File lib/dmail/utils.rb, line 9 def setup_pager! page end