Class: Dolarblue

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

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
  @card     = Card.new
  self
end

Class Method Details

.get_cardblue_outputString

Returns all the dollar card exchange ‘Blue’ vs ‘Card’ info

suitable for user printing analysis

Returns:

  • (String)

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



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

def get_cardblue_output
  new.update!(false).cardblue_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

#cardblue_outputString

Output string to be used by the binary ‘cardblue`

Returns:

  • (String)

    the output with card/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 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_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_card_percent
  gap_card = @blue.sell / @card.sell - 1
  (gap_card * 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
  "\#{@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

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