quote-only 0.1.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/quote-only.rb +18 -3
- data/test/test-quote-only.rb +15 -11
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 727366627edce9fea3d608a92cddca959c5bc9ee
|
4
|
+
data.tar.gz: 95537ec529c53bc0143935e66d32b879ae3fe40c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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)
|
data/test/test-quote-only.rb
CHANGED
@@ -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 =>
|
8
|
-
cnn_market_tests.push({ :symbol => 'sandp', :friendly_name => 'S&P', :decimal_places =>
|
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 =
|
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 => '
|
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 => '
|
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:
|
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-
|
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
|
16
|
-
supported via money.com. Treasuries are supported via
|
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: []
|