Module: EGPRatesCLI
- Defined in:
- lib/EGP_Rates_CLI.rb,
lib/EGP_Rates_CLI/config.rb
Overview
CLI
Defined Under Namespace
Classes: Config
Constant Summary collapse
- BANKS =
i(CBE NBE CIB AAIB BanqueDuCaire BanqueMisr SuezCanalBank AlBarakaBank AlAhliBankOfKuwait SAIB MIDB UBE CAE EDBE AlexBank Blom ADIB EGB NBG FaisalBank)
- CURRENCIES =
i(USD EUR GBP CHF SAR JPY KWD AED AUD BHD CAD DKK JOD NOK OMR QAR SEK CNY)
Class Method Summary collapse
Class Method Details
.config ⇒ Object
17 18 19 |
# File 'lib/EGP_Rates_CLI.rb', line 17 def self.config @@configurtion ||= Config.config end |
.render(table) ⇒ Object
68 69 70 71 72 |
# File 'lib/EGP_Rates_CLI.rb', line 68 def self.render(table) TTY::Command.new(printer: :quiet).run('clear') TTY::Prompt.new.say("Updated at: #{Time.now}") puts table.render(:unicode, width: 80, resize: true) end |
.run(config) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/EGP_Rates_CLI.rb', line 30 def self.run(config) table = TTY::Table.new( header: [ { value: 'Bank', alignment: :left }, { value: 'Currency', alignment: :center }, { value: 'Buy', alignment: :left }, { value: 'Sell', alignment: :left} ] ) banks = config[:bank].empty? ? BANKS : config[:bank] currencies = config[:currency].empty? ? CURRENCIES : config[:currency] banks.each do |bank| currencies.each do |currency| begin rates = EGPRates.const_get(bank).new.exchange_rates table << [ { value: bank.to_s, alignment: :left }, { value: currency.to_s, alignment: :center }, { value: rates[:buy][currency.to_sym], alignment: :left }, { value: rates[:sell][currency.to_sym], alignment: :left } ] rescue EGPRates::ResponseError table << [ { value: bank.to_s, alignment: :left }, { value: currency.to_s, alignment: :center }, { value: 'N/A', alignment: :center }, { value: 'N/A', alignment: :center } ] next end end end render(table) sleep config[:interval] * 60 run(config) end |
.start ⇒ Object
21 22 23 |
# File 'lib/EGP_Rates_CLI.rb', line 21 def self.start run(config) end |
.stop ⇒ Object
25 26 27 28 |
# File 'lib/EGP_Rates_CLI.rb', line 25 def self.stop TTY::Prompt.new.say("\nGoodbye ;)") exit 0 end |