Module: FtgOptions

Included in:
Ftg
Defined in:
lib/ftg/ftg_options.rb

Instance Method Summary collapse

Instance Method Details

#day_optionObject

day, not gay



10
11
12
13
14
15
16
17
# File 'lib/ftg/ftg_options.rb', line 10

def day_option
  day_option = get_option(['-d', '--day'])
  day_option ||= '0'

  Utils.is_integer?(day_option) ?
    Time.at(Time.now.to_i - day_option.to_i * 86400).strftime('%F') :
    Date.parse(day_option).strftime('%F')
end

#fail(message = nil) ⇒ Object



24
25
26
27
# File 'lib/ftg/ftg_options.rb', line 24

def fail(message = nil)
  STDERR.puts message if message
  exit(1)
end

#get_command(name) ⇒ Object



19
20
21
22
# File 'lib/ftg/ftg_options.rb', line 19

def get_command(name)
  @commands.find { |cmd_name, _| cmd_name.to_s.start_with?(name) } ||
    @commands.find { |_, cmd| cmd[:aliases] && cmd[:aliases].any? { |a| a.to_s.start_with?(name) } }
end

#get_option(names) ⇒ Object



2
3
4
5
6
7
# File 'lib/ftg/ftg_options.rb', line 2

def get_option(names)
  ARGV.each_with_index do |opt_name, i|
    return (ARGV[i + 1] || 1) if names.include?(opt_name)
  end
  nil
end