Class: QuoteOnly
- Inherits:
-
Object
- Object
- QuoteOnly
- Defined in:
- lib/quote-only.rb
Direct Known Subclasses
ApmexGoldQuoteOnly, ApmexSilverQuoteOnly, BloombergQuoteOnly, CnnMarketQuoteOnly, CnnQuoteOnly
Instance Attribute Summary collapse
-
#css ⇒ Object
Returns the value of attribute css.
-
#friendly_name ⇒ Object
Returns the value of attribute friendly_name.
-
#quote ⇒ Object
Returns the value of attribute quote.
-
#symbol ⇒ Object
Returns the value of attribute symbol.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize(options) ⇒ QuoteOnly
constructor
A new instance of QuoteOnly.
- #match ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(options) ⇒ QuoteOnly
Returns a new instance of QuoteOnly.
7 8 9 10 11 |
# File 'lib/quote-only.rb', line 7 def initialize() @symbol = [:symbol] @friendly_name = [:friendly_name] @decimal_places = [:decimal_places] end |
Instance Attribute Details
#css ⇒ Object
Returns the value of attribute css.
5 6 7 |
# File 'lib/quote-only.rb', line 5 def css @css end |
#friendly_name ⇒ Object
Returns the value of attribute friendly_name.
5 6 7 |
# File 'lib/quote-only.rb', line 5 def friendly_name @friendly_name end |
#quote ⇒ Object
Returns the value of attribute quote.
5 6 7 |
# File 'lib/quote-only.rb', line 5 def quote @quote end |
#symbol ⇒ Object
Returns the value of attribute symbol.
5 6 7 |
# File 'lib/quote-only.rb', line 5 def symbol @symbol end |
#url ⇒ Object
Returns the value of attribute url.
5 6 7 |
# File 'lib/quote-only.rb', line 5 def url @url end |
Instance Method Details
#match ⇒ Object
13 14 15 16 |
# File 'lib/quote-only.rb', line 13 def match page = Nokogiri::HTML(open(@url)) @quote = page.css(@css).text.gsub(/[$,]/, '').to_f end |
#to_s ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/quote-only.rb', line 18 def to_s decimal_places_string = '0' if(@decimal_places > 0) decimal_places_string = @decimal_places.to_s end quote_rounded = ('%.' + decimal_places_string + 'f') % @quote.round(@decimal_places) s = @friendly_name + ' (' + @symbol + ') ' + quote_rounded.to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1,').reverse end |