Class: Dolarblue::XChange Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/dolarblue/xchange.rb

Overview

This class is abstract.

Base class for Blue, Official and Bolsa used to hold sell/buy values functionality

Direct Known Subclasses

Blue, Bolsa, Official

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = Configuration.instance) ⇒ self

Create a new Blue / Official / Bolsa instance to work later on

Parameters:

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

    the configuration instance



17
18
19
20
# File 'lib/dolarblue/xchange.rb', line 17

def initialize(config = Configuration.instance)
  @config = config.defaults
  self
end

Instance Attribute Details

#buyObject (readonly)

Returns the value of attribute buy.



10
11
12
# File 'lib/dolarblue/xchange.rb', line 10

def buy
  @buy
end

#sellObject (readonly)

Returns the value of attribute sell.



10
11
12
# File 'lib/dolarblue/xchange.rb', line 10

def sell
  @sell
end

Instance Method Details

#buy_outputString

Return a formatted string suitable for user output with current buy value

Returns:

  • (String)

    formatted output buy exchange value



47
48
49
# File 'lib/dolarblue/xchange.rb', line 47

def buy_output
  '%.2f' % buy
end

#cnameString

Return the demodulized class name

Returns:

  • (String)

    demodulized class name string



25
26
27
# File 'lib/dolarblue/xchange.rb', line 25

def cname
  Inflector.demodulize(self.class.name)
end

#extract_values(doc) ⇒ Object

Performs buy and sell values extraction from a Nokogiri::HTML Document

Parameters:

  • doc (Nokogiri::HTML)

    the html document to extract values from



39
40
41
42
# File 'lib/dolarblue/xchange.rb', line 39

def extract_values(doc)
  @buy  = extract_val(doc, 'buy')
  @sell = extract_val(doc, 'sell')
end

#nameString

Return downcased demodulized class name

Returns:

  • (String)

    downcased demodulized class name string



32
33
34
# File 'lib/dolarblue/xchange.rb', line 32

def name
  cname.downcase
end

#outputString

Return a formatted string suitable for user output with current buy and sell values

Returns:

  • (String)

    formatted output with buy and sell exchange values



61
62
63
64
65
66
# File 'lib/dolarblue/xchange.rb', line 61

def output
  t = cname.ljust(10, '.')
  b = buy_output.rjust(5)
  s = sell_output.rjust(5)
  %Q{- Dollar #{t}..: #{b} / #{s}}
end

#sell_outputString

Return a formatted string suitable for user output with current sell value

Returns:

  • (String)

    formatted output sell exchange value



54
55
56
# File 'lib/dolarblue/xchange.rb', line 54

def sell_output
  '%.2f' % sell
end