Class: Dolarblue
- Inherits:
-
Object
- Object
- Dolarblue
- Defined in:
- lib/dolarblue.rb,
lib/dolarblue/blue.rb,
lib/dolarblue/card.rb,
lib/dolarblue/version.rb,
lib/dolarblue/xchange.rb,
lib/dolarblue/official.rb,
lib/dolarblue/inflector.rb,
lib/dolarblue/configuration.rb,
lib/dolarblue/instance_methods.rb
Overview
Main class used as builder and also as Dolarblue namespace
Defined Under Namespace
Modules: Inflector Classes: Blue, Card, Configuration, Official, XChange
Constant Summary collapse
- VERSION =
"0.5.1"
Class Method Summary collapse
-
.get_cardblue_output ⇒ String
Returns all the dollar card exchange ‘Blue’ vs ‘Card’ info suitable for user printing analysis.
-
.get_output ⇒ String
Returns all the dollar exchange ‘Blue’ vs ‘Official’ values and percentiles suitable for user printing.
Instance Method Summary collapse
-
#cardblue_output ⇒ String
Output string to be used by the binary ‘cardblue`.
-
#gap_card_percent ⇒ Float
Returns the gap percentile between the real (blue) dollar value versus the official.
-
#gap_official_percent ⇒ Float
Returns the gap percentile (e.g. 60) between the real (blue) dollar value versus the official.
-
#initialize(config = Configuration.instance) ⇒ Dolarblue
constructor
Create a new Dolarblue instance to work later on.
-
#output ⇒ String
Output string to be used by the binary ‘dolarblue`.
-
#update!(log = true) ⇒ Dolarblue
Connect to the source and retrieve dollar exchange values.
Constructor Details
#initialize(config = Configuration.instance) ⇒ Dolarblue
Create a new Dolarblue instance to work later on
16 17 18 19 20 21 22 |
# File 'lib/dolarblue/instance_methods.rb', line 16 def initialize(config = Configuration.instance) @config = config.defaults @blue = Blue.new @official = Official.new @card = Card.new self end |
Class Method Details
.get_cardblue_output ⇒ String
Returns all the dollar card exchange ‘Blue’ vs ‘Card’ info
suitable for user printing analysis
20 21 22 |
# File 'lib/dolarblue.rb', line 20 def get_cardblue_output new.update!(false).cardblue_output end |
.get_output ⇒ String
Returns all the dollar exchange ‘Blue’ vs ‘Official’ values and percentiles
suitable for user printing
12 13 14 |
# File 'lib/dolarblue.rb', line 12 def get_output new.update!.output end |
Instance Method Details
#cardblue_output ⇒ String
Output string to be used by the binary ‘cardblue`
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/dolarblue/instance_methods.rb', line 79 def cardblue_output n = 27 bol_discount = 0.97 card_delay_add = 1.01 payo_discount = 0.967 net_ticket = 375 sell_ticket = 396.2 real = (@blue.sell * bol_discount).round(2) profit = n * (real * net_ticket * payo_discount - @card.sell * card_delay_add * sell_ticket) now = Time.now.localtime.strftime("%H:%M:%S") "Card[\#{@card.sell_output}] Blue[\#{@blue.sell_output}] Gap[\#{gap_card_percent}%] \#{now}\n\#{profit.round(0)}=\#{n}*(\#{real}*\#{net_ticket}*\#{payo_discount}-\#{@card.sell}*\#{card_delay_add}*\#{sell_ticket})\n OUTPUT\nend\n" |
#gap_card_percent ⇒ Float
Returns the gap percentile between the real (blue) dollar value versus the official
54 55 56 57 |
# File 'lib/dolarblue/instance_methods.rb', line 54 def gap_card_percent gap_card = @blue.sell / @card.sell - 1 (gap_card * 100).round(0) end |
#gap_official_percent ⇒ Float
Returns the gap percentile (e.g. 60) between the real (blue) dollar value versus the official
46 47 48 49 |
# File 'lib/dolarblue/instance_methods.rb', line 46 def gap_official_percent gap_official = @blue.sell / @official.sell - 1 (gap_official * 100).round(0) end |
#output ⇒ String
Output string to be used by the binary ‘dolarblue`
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/dolarblue/instance_methods.rb', line 62 def output "\#{@official.output}\n\#{@card.output}\n\#{@blue.output}\n\n- Gap card.......blue: \#{gap_card_percent}%\n- Gap official...blue: \#{gap_official_percent}%\n\nInformation source:\n\#{@config.base_url}\n OUTPUT\nend\n" |
#update!(log = true) ⇒ Dolarblue
Connect to the source and retrieve dollar exchange values
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/dolarblue/instance_methods.rb', line 29 def update!(log=true) base_url = @config.base_url fail ArgumentError, "Need base_url configuration to know where to web-scrape from. Current value: #{base_url}" if base_url.empty? log "Obtaining latest AR$ vs US$ exchange values..." if log html_file = open(base_url) log "Parsing values..." if log parse_values Nokogiri::HTML(html_file) log "\nDone: #{Time.now.localtime}\n" if log self end |