Class: Timeprice::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/timeprice/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.all_commandsObject

Thor 1.5 ships a built-in ‘tree` command on every subclass. Strip it from this subclass — it’s an internal debugging aid that leaks into our help output. all_commands inherits from the base Thor class, so filter it on read.



13
14
15
# File 'lib/timeprice/cli.rb', line 13

def self.all_commands
  super.except("tree")
end

.exit_on_failure?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/timeprice/cli.rb', line 19

def self.exit_on_failure?
  true
end

Instance Method Details

#compare(amount) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/timeprice/cli.rb', line 56

def compare(amount)
  with_error_handling do
    from_tuple = parse_compare_token(options[:from], label: "--from")
    to_tuple   = parse_compare_token(options[:to],   label: "--to")
    result = Timeprice.compare(
      amount: Float(amount),
      from: from_tuple,
      to: to_tuple
    )
    emit_compare(result)
  end
end

#fx(amount, from_currency, to_currency) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/timeprice/cli.rb', line 41

def fx(amount, from_currency, to_currency)
  with_error_handling do
    result = Timeprice.exchange(
      amount: Float(amount),
      from: from_currency,
      to: to_currency,
      date: options[:date]
    )
    emit_exchange(result)
  end
end

#inflation(amount) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/timeprice/cli.rb', line 27

def inflation(amount)
  with_error_handling do
    result = Timeprice.inflation(
      amount: Float(amount),
      from: options[:from],
      to: options[:to],
      country: options[:country]
    )
    emit_inflation(result)
  end
end

#sourcesObject



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/timeprice/cli.rb', line 70

def sources
  list = Timeprice::Sources.list
  if options[:json]
    say JSON.generate(list)
  else
    list.each do |s|
      say s[:name].to_s
      say "  id:           #{s[:id]}"
      say "  license:      #{s[:license]}"
      say "  license_url:  #{s[:license_url]}"
      say "  attribution:  #{s[:attribution]}"
      say "  coverage:     #{s[:coverage]}"
      say ""
    end
  end
end

#versionObject



88
89
90
91
92
93
94
# File 'lib/timeprice/cli.rb', line 88

def version
  if options[:json]
    say JSON.generate({ version: Timeprice::VERSION, repo: "patrick204nqh/timeprice" })
  else
    say "timeprice #{Timeprice::VERSION} — patrick204nqh/timeprice"
  end
end