Class: Dolarblue::XChange Abstract
- Inherits:
-
Object
- Object
- Dolarblue::XChange
- Defined in:
- lib/dolarblue/xchange.rb
Overview
Base class for Blue, Official and Bolsa used to hold sell/buy values functionality
Instance Attribute Summary collapse
-
#buy ⇒ Object
readonly
Returns the value of attribute buy.
-
#sell ⇒ Object
readonly
Returns the value of attribute sell.
Instance Method Summary collapse
-
#buy_output ⇒ String
Return a formatted string suitable for user output with current buy value.
-
#cname ⇒ String
Return the demodulized class name.
-
#extract_values(doc) ⇒ Object
Performs buy and sell values extraction from a Nokogiri::HTML Document.
-
#initialize(config = Configuration.instance) ⇒ self
constructor
Create a new Blue / Official / Bolsa instance to work later on.
-
#name ⇒ String
Return downcased demodulized class name.
-
#output ⇒ String
Return a formatted string suitable for user output with current buy and sell values.
-
#sell_output ⇒ String
Return a formatted string suitable for user output with current sell value.
Constructor Details
#initialize(config = Configuration.instance) ⇒ self
Create a new Blue / Official / Bolsa instance to work later on
17 18 19 20 |
# File 'lib/dolarblue/xchange.rb', line 17 def initialize(config = Configuration.instance) @config = config.defaults self end |
Instance Attribute Details
#buy ⇒ Object (readonly)
Returns the value of attribute buy.
10 11 12 |
# File 'lib/dolarblue/xchange.rb', line 10 def buy @buy end |
#sell ⇒ Object (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_output ⇒ String
Return a formatted string suitable for user output with current buy value
47 48 49 |
# File 'lib/dolarblue/xchange.rb', line 47 def buy_output '%.2f' % buy end |
#cname ⇒ String
Return the demodulized class name
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
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 |
#name ⇒ String
Return downcased demodulized class name
32 33 34 |
# File 'lib/dolarblue/xchange.rb', line 32 def name cname.downcase end |
#output ⇒ String
Return a formatted string suitable for user output with current buy and sell 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_output ⇒ String
Return a formatted string suitable for user output with current sell value
54 55 56 |
# File 'lib/dolarblue/xchange.rb', line 54 def sell_output '%.2f' % sell end |