Class: Timeprice::CLI
- Inherits:
-
Thor
- Object
- Thor
- Timeprice::CLI
- Defined in:
- lib/timeprice/cli.rb
Class Method Summary collapse
-
.all_commands ⇒ Object
Thor 1.5 ships a built-in ‘tree` command on every subclass.
- .exit_on_failure? ⇒ Boolean
Instance Method Summary collapse
- #compare(amount) ⇒ Object
- #fx(amount, from_currency, to_currency) ⇒ Object
- #inflation(amount) ⇒ Object
- #sources ⇒ Object
- #version ⇒ Object
Class Method Details
.all_commands ⇒ Object
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
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([:from], label: "--from") to_tuple = parse_compare_token([: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: [: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: [:from], to: [:to], country: [:country] ) emit_inflation(result) end end |
#sources ⇒ Object
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 [: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 |