Module: Dolarblue::InstanceMethods

Included in:
Dolarblue
Defined in:
lib/dolarblue/instance_methods.rb

Instance Method Summary collapse

Instance Method Details

#card_fee_sell_valueObject



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_valuesString

Return a string suitable for user output about dollar “tarjeta” values

Returns:

  • (String)

    output exchange values 1 line string



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_cardFloat

Returns the gap between the real (blue) dollar value versus the dollar “tarjeta” vale

Returns:

  • (Float)

    percentile value between 0..1



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_percentFloat

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

Returns:

  • (Float)

    percentile value between 0..100



65
66
67
# File 'lib/dolarblue/instance_methods.rb', line 65

def gap_card_percent
  (gap_card * 100).round(0)
end

#gap_officialFloat

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

Returns:

  • (Float)

    percentile value between 0..1



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_percentFloat

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

Returns:

  • (Float)

    percentile value between 0..100



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

Parameters:

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

    the configuration instance

Returns:



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

#outputString

Output string to be used by the binary ‘dolarblue`

Returns:

  • (String)

    the output with dollar exchange information



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

Returns:

  • (self)


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

Returns:

  • (true, false)

    boolean state



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

def valid?
  @blue.valid? && @official.valid?
end