Module: Dolarblue::InstanceMethods
- Included in:
- Dolarblue
- Defined in:
- lib/dolarblue/instance_methods.rb
Instance Method Summary collapse
- #card_fee_sell_value ⇒ Object
-
#card_output_values ⇒ String
Return a string suitable for user output about dollar “tarjeta” values.
-
#gap_card ⇒ Float
Returns the gap between the real (blue) dollar value versus the dollar “tarjeta” vale.
-
#gap_card_percent ⇒ Float
Returns the gap percentile between the real (blue) dollar value versus the official.
-
#gap_official ⇒ Float
Returns the gap between the real (blue) dollar value versus the official.
-
#gap_official_percent ⇒ Float
Returns the gap percentile between the real (blue) dollar value versus the official.
-
#initialize(config = Configuration.instance) ⇒ Dolarblue
Create a new Dolarblue instance to work later on.
-
#output ⇒ String
Output string to be used by the binary ‘dolarblue`.
-
#update! ⇒ self
Connect to the source and retrieve dollar exchange values.
-
#valid? ⇒ true, false
Returns current object state, whether valid or not.
Instance Method Details
#card_fee_sell_value ⇒ Object
50 51 52 |
# File 'lib/dolarblue/instance_methods.rb', line 50 def card_fee_sell_value (@official.sell_value * @card_fee).round(2) end |
#card_output_values ⇒ String
Return a string suitable for user output about dollar “tarjeta” values
72 73 74 |
# File 'lib/dolarblue/instance_methods.rb', line 72 def card_output_values %Q{- Dolar "Tarjeta": n/a / #{'%.2f' % card_fee_sell_value} (Updated #{@official.updated_ago})} end |
#gap_card ⇒ Float
Returns the gap between the real (blue) dollar value versus the dollar “tarjeta” vale
57 58 59 60 |
# File 'lib/dolarblue/instance_methods.rb', line 57 def gap_card fail "Need blue and official values to be setup before calculating the gap" unless @blue.sell_value && @blue.sell_value > 0 && @official.sell_value && @official.sell_value > 0 (@blue.sell_value / card_fee_sell_value - 1) end |
#gap_card_percent ⇒ Float
Returns the gap percentile between the real (blue) dollar value versus the official
65 66 67 |
# File 'lib/dolarblue/instance_methods.rb', line 65 def gap_card_percent (gap_card * 100).round(0) end |
#gap_official ⇒ Float
Returns the gap between the real (blue) dollar value versus the official
38 39 40 41 |
# File 'lib/dolarblue/instance_methods.rb', line 38 def gap_official fail "Need blue and official values to be setup before calculating the gap" unless @blue.sell_value && @blue.sell_value > 0 && @official.sell_value && @official.sell_value > 0 (@blue.sell_value / @official.sell_value - 1) end |
#gap_official_percent ⇒ Float
Returns the gap percentile between the real (blue) dollar value versus the official
46 47 48 |
# File 'lib/dolarblue/instance_methods.rb', line 46 def gap_official_percent (gap_official * 100).round(0) end |
#initialize(config = Configuration.instance) ⇒ Dolarblue
Create a new Dolarblue instance to work later on
9 10 11 12 13 14 15 |
# File 'lib/dolarblue/instance_methods.rb', line 9 def initialize(config = Configuration.instance) fail ArgumentError, "Expected a Dolarblue::Configuration instance as argument" unless config.is_a?(Configuration) @card_fee = config.card_fee @blue = Dolarblue::Exchange.new('Blue', config.blue_screen_name, config.blue_regexp, config.buy_sell_blue_factor) @official = Dolarblue::Exchange.new('Official', config.official_screen_name, config.official_regexp, config.buy_sell_official_factor) self end |
#output ⇒ String
Output string to be used by the binary ‘dolarblue`
79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/dolarblue/instance_methods.rb', line 79 def output <<-OUTPUT #{@official.output_values} #{card_output_values} #{@blue.output_values} - Gap "tarjeta"..: #{gap_card_percent}% - Gap (official).: #{gap_official_percent}% Information sources: #{@official.output_link} #{@blue.output_link} OUTPUT end |
#update! ⇒ self
Connect to the source and retrieve dollar exchange values
27 28 29 30 31 32 33 |
# File 'lib/dolarblue/instance_methods.rb', line 27 def update! print "Obtaining latest AR$ vs US$ exchange values..." @blue.update! @official.update! print "Done.\n\n" self end |
#valid? ⇒ true, false
Returns current object state, whether valid or not
20 21 22 |
# File 'lib/dolarblue/instance_methods.rb', line 20 def valid? @blue.valid? && @official.valid? end |