Class: Dolarblue

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(config = Configuration.instance) ⇒ Dolarblue

Create a new Dolarblue instance to work later on

Parameters:

  • config (Configuration) (defaults to: Configuration.instance)

    the configuration instance



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_outputString

Returns all the dollar bolsa exchange ‘Blue’ vs ‘Bolsa’ info

suitable for user printing analysis

Returns:

  • (String)

    with all dollar exchange ‘Blue’ vs ‘Bolsa’ values



20
21
22
# File 'lib/dolarblue.rb', line 20

def get_bolsablue_output
  new.update!(false).bolsablue_output
end

.get_outputString

Returns all the dollar exchange ‘Blue’ vs ‘Official’ values and percentiles

suitable for user printing

Returns:

  • (String)

    with all dollar exchange ‘Blue’ vs ‘Official’ values



12
13
14
# File 'lib/dolarblue.rb', line 12

def get_output
  new.update!.output
end

Instance Method Details

#bolsablue_outputString

Output string to be used by the binary ‘bolsablue`

Returns:

  • (String)

    the output with bolsa/dollar exchange info



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_percentFloat

Returns the gap percentile between the real (blue) dollar value versus the official

Returns:

  • (Float)

    percentile value between 0..100



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_percentFloat

Returns the gap percentile (e.g. 60) between the real (blue) dollar value versus the official

Returns:

  • (Float)

    percentile value between 0..100



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

#outputString

Output string to be used by the binary ‘dolarblue`

Returns:

  • (String)

    the output with dollar exchange information



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

Parameters:

  • log (Boolean) (defaults to: true)

    weather to show log standard outputs or not

Returns:



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