Class: Dolarblue
- Inherits:
-
Object
- Object
- Dolarblue
- Defined in:
- lib/dolarblue.rb,
lib/dolarblue/blue.rb,
lib/dolarblue/bolsa.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, Bolsa, Configuration, Official, XChange
Constant Summary collapse
- VERSION =
"0.6.0"
Class Method Summary collapse
-
.get_bolsablue_output ⇒ String
Returns all the dollar bolsa exchange ‘Blue’ vs ‘Bolsa’ 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
-
#bolsablue_output ⇒ String
Output string to be used by the binary ‘bolsablue`.
-
#gap_bolsa_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 @bolsa = Bolsa.new self end |
Class Method Details
.get_bolsablue_output ⇒ String
Returns all the dollar bolsa exchange ‘Blue’ vs ‘Bolsa’ info
suitable for user printing analysis
20 21 22 |
# File 'lib/dolarblue.rb', line 20 def get_bolsablue_output new.update!(false).bolsablue_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
#bolsablue_output ⇒ String
Output string to be used by the binary ‘bolsablue`
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 bolsablue_output n = 27 bol_discount = 0.97 bolsa_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 - @bolsa.sell * bolsa_delay_add * sell_ticket) now = Time.now.localtime.strftime("%H:%M:%S") <<-OUTPUT Bolsa[#{@bolsa.sell_output}] Blue[#{@blue.sell_output}] Gap[#{gap_bolsa_percent}%] #{now} #{profit.round(0)}=#{n}*(#{real}*#{net_ticket}*#{payo_discount}-#{@bolsa.sell}*#{bolsa_delay_add}*#{sell_ticket}) OUTPUT end |
#gap_bolsa_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_bolsa_percent gap_bolsa = @blue.sell / @bolsa.sell - 1 (gap_bolsa * 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 <<-OUTPUT #{@official.output} #{@bolsa.output} #{@blue.output} - Gap bolsa......blue: #{gap_bolsa_percent}% - Gap official...blue: #{gap_official_percent}% Information source: #{@config.base_url} OUTPUT end |
#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 |