quote-only 0.1.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a42e8e027588fa6debdf8243bdca4e728be0d0fd
4
- data.tar.gz: c60fada8938fc8c6efa6f3ebfeb0b7b6b51c0d3c
3
+ metadata.gz: 727366627edce9fea3d608a92cddca959c5bc9ee
4
+ data.tar.gz: 95537ec529c53bc0143935e66d32b879ae3fe40c
5
5
  SHA512:
6
- metadata.gz: 556680bcad917ff595b8c6bdd11ea25484e9d790d4d86fe0dd0e10a6e9da4ed7fb1bc40fd28ccc4cc9bd55dcf954e16f2155374af319f9764d9ca5489565e22f
7
- data.tar.gz: ecab89d82810ffdaed5a0ec703c966b6c0a1e844087770e147ec63b0891f2922bbfd2bdb257f830541179c63e17c4b0dc9e3f16305f01c50015ae494ac8a7150
6
+ metadata.gz: b0a7a322f8eaaa52d51e62f4aaf2d3367f4c439b2f4088b981814b30555beaf7559bd0b3eaf0f37a5246ecc1a606f402292db0c72b3a21a8b1355f04d0ac706e
7
+ data.tar.gz: a94d6820e0652fd4942e8c61c739409e505ad73744fd967785701c8325d1811cef34e1a1e0a1b263d0ce9cfd1d233d669e4563184164bb2ca44e087c3eb7b1f0
data/lib/quote-only.rb CHANGED
@@ -4,7 +4,7 @@ require 'open-uri'
4
4
 
5
5
  class QuoteOnly
6
6
  attr_accessor :css, :url, :symbol, :friendly_name, :quote
7
-
7
+
8
8
  def initialize(options)
9
9
  @symbol = options[:symbol]
10
10
  @friendly_name = options[:friendly_name]
@@ -15,9 +15,15 @@ class QuoteOnly
15
15
  page = Nokogiri::HTML(open(@url))
16
16
  @quote = page.css(@css).text.gsub(/[$,]/, '').to_f
17
17
  end
18
-
18
+
19
19
  def to_s
20
- quote_rounded = ('%.' + @decimal_places.to_s + 'f') % @quote.round(@decimal_places)
20
+ decimal_places_string = '0'
21
+
22
+ if(@decimal_places > 0)
23
+ decimal_places_string = @decimal_places.to_s
24
+ end
25
+
26
+ quote_rounded = ('%.' + decimal_places_string + 'f') % @quote.round(@decimal_places)
21
27
  s = @friendly_name + ' (' + @symbol + ') ' + quote_rounded.to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1,').reverse
22
28
  end
23
29
  end
@@ -31,6 +37,15 @@ class CnnMarketQuoteOnly < QuoteOnly
31
37
  end
32
38
  end
33
39
 
40
+ class CnnQuoteOnly < QuoteOnly
41
+ def initialize(options)
42
+ super(options)
43
+ @css = 'td.wsod_last > span'
44
+ @url = 'http://money.cnn.com/quote/quote.html?symb=' + @symbol
45
+ match()
46
+ end
47
+ end
48
+
34
49
  class BloombergQuoteOnly < QuoteOnly
35
50
  def initialize(options)
36
51
  super(options)
@@ -4,25 +4,29 @@ require 'quote-only'
4
4
  class QuoteOnlyTest < Minitest::Test
5
5
  def test_
6
6
  cnn_market_tests = []
7
- cnn_market_tests.push({ :symbol => 'dow', :friendly_name => 'Dow', :decimal_places => 0 })
8
- cnn_market_tests.push({ :symbol => 'sandp', :friendly_name => 'S&P', :decimal_places => 0 })
9
-
7
+ cnn_market_tests.push({ :symbol => 'dow', :friendly_name => 'Dow', :decimal_places => -3 })
8
+ cnn_market_tests.push({ :symbol => 'sandp', :friendly_name => 'S&P', :decimal_places => -2 })
9
+
10
10
  cnn_market_tests.each do |c|
11
11
  f = CnnMarketQuoteOnly.new(c)
12
12
  puts f
13
- assert f.quote.is_a? Float
13
+ assert f.quote.is_a? Float
14
14
  end
15
-
16
- f = BloombergQuoteOnly.new({ :symbol => 'USGG10YR:IND', :friendly_name => '10 Year', :decimal_places => 2 })
15
+
16
+ f = CnnQuoteOnly.new({ :symbol => 'XBT', :friendly_name => 'Bitcoin', :decimal_places => -2 })
17
+ puts f
18
+ assert f.quote.is_a? Float
19
+
20
+ f = BloombergQuoteOnly.new({ :symbol => 'USGG10YR:IND', :friendly_name => '10 Year', :decimal_places => 0 })
17
21
  puts f
18
22
  assert f.quote.is_a? Float
19
-
20
- f = ApmexGoldQuoteOnly.new({ :symbol => 'Gold Spot', :friendly_name => 'Gold', :decimal_places => 0 })
23
+
24
+ f = ApmexGoldQuoteOnly.new({ :symbol => 'oz', :friendly_name => 'Gold', :decimal_places => -2 })
21
25
  puts f
22
26
  assert f.quote.is_a? Float
23
-
24
- f = ApmexSilverQuoteOnly.new({ :symbol => 'Silver Spot', :friendly_name => 'Silver', :decimal_places => 0 })
27
+
28
+ f = ApmexSilverQuoteOnly.new({ :symbol => 'oz', :friendly_name => 'Silver', :decimal_places => 0 })
25
29
  puts f
26
- assert f.quote.is_a? Float
30
+ assert f.quote.is_a? Float
27
31
  end
28
32
  end
metadata CHANGED
@@ -1,20 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quote-only
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - cscribn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-21 00:00:00.000000000 Z
11
+ date: 2015-10-07 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Most finincial websites show the daily change of a financial asset, along
14
14
  with its quote. This can be distracting to long-term investors attempting to "stay
15
- the course". The purpose of this gem is to provide only the quote. Markets are
16
- supported via money.com. Treasuries are supported via Bloomberg. Precious Metals
17
- are supported using apmex.com.
15
+ the course". The purpose of this gem is to provide only the quote. Markets and
16
+ quotes are supported via money.com. Treasuries are supported via bloomberg.com. Precious
17
+ Metals are supported using apmex.com.
18
18
  email:
19
19
  executables: []
20
20
  extensions: []