class Dolarblue::XChange
Base class for Blue
, Official
and Bolsa
used to hold sell/buy values functionality
@abstract
Attributes
Public Class Methods
Public Instance Methods
Return a formatted string suitable for user output with current buy value
@return [String] formatted output buy exchange value
# File lib/dolarblue/xchange.rb, line 47 def buy_output '%.2f' % buy end
Return the demodulized class name
@return [String] demodulized class name string
# File lib/dolarblue/xchange.rb, line 25 def cname Inflector.demodulize(self.class.name) end
Performs buy and sell values extraction from a Nokogiri::HTML Document
@param [Nokogiri::HTML] doc the html document to extract values from
# File lib/dolarblue/xchange.rb, line 39 def extract_values(doc) @buy = extract_val(doc, 'buy') @sell = extract_val(doc, 'sell') end
Return downcased demodulized class name
@return [String] downcased demodulized class name string
# File lib/dolarblue/xchange.rb, line 32 def name cname.downcase end
Return a formatted string suitable for user output with current buy and sell values
@return [String] formatted output with buy and sell exchange values
# 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
Return a formatted string suitable for user output with current sell value
@return [String] formatted output sell exchange value
# File lib/dolarblue/xchange.rb, line 54 def sell_output '%.2f' % sell end
Protected Instance Methods
Extract individual buy/sell values from a Nokogiri::HTML Document
@param doc [Nokogiri::HTML] the html document to extract values from @param type [String] the dollar type, can be ‘blue’, ‘official’, ‘bolsa’
@raise [RuntimeError] if unable to proper buy/sell value for current dollar type
@private
# File lib/dolarblue/xchange.rb, line 78 def extract_val(doc, type) xpath = @config[name][type].xpath value = doc.xpath(xpath).text.gsub(',', '.') fail RuntimeError, "Failed to capture #{name} #{type} value" if value.empty? value.to_f.round(2) end