quote-only 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a42e8e027588fa6debdf8243bdca4e728be0d0fd
4
+ data.tar.gz: c60fada8938fc8c6efa6f3ebfeb0b7b6b51c0d3c
5
+ SHA512:
6
+ metadata.gz: 556680bcad917ff595b8c6bdd11ea25484e9d790d4d86fe0dd0e10a6e9da4ed7fb1bc40fd28ccc4cc9bd55dcf954e16f2155374af319f9764d9ca5489565e22f
7
+ data.tar.gz: ecab89d82810ffdaed5a0ec703c966b6c0a1e844087770e147ec63b0891f2922bbfd2bdb257f830541179c63e17c4b0dc9e3f16305f01c50015ae494ac8a7150
@@ -0,0 +1,71 @@
1
+ require 'rubygems'
2
+ require 'nokogiri'
3
+ require 'open-uri'
4
+
5
+ class QuoteOnly
6
+ attr_accessor :css, :url, :symbol, :friendly_name, :quote
7
+
8
+ def initialize(options)
9
+ @symbol = options[:symbol]
10
+ @friendly_name = options[:friendly_name]
11
+ @decimal_places = options[:decimal_places]
12
+ end
13
+
14
+ def match
15
+ page = Nokogiri::HTML(open(@url))
16
+ @quote = page.css(@css).text.gsub(/[$,]/, '').to_f
17
+ end
18
+
19
+ def to_s
20
+ quote_rounded = ('%.' + @decimal_places.to_s + 'f') % @quote.round(@decimal_places)
21
+ s = @friendly_name + ' (' + @symbol + ') ' + quote_rounded.to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1,').reverse
22
+ end
23
+ end
24
+
25
+ class CnnMarketQuoteOnly < QuoteOnly
26
+ def initialize(options)
27
+ super(options)
28
+ @css = 'td.wsod_lastIndex > span'
29
+ @url = 'http://money.cnn.com/data/markets/' + @symbol + '/'
30
+ match()
31
+ end
32
+ end
33
+
34
+ class BloombergQuoteOnly < QuoteOnly
35
+ def initialize(options)
36
+ super(options)
37
+ @css = 'div.price-container > div.price'
38
+ @url = 'http://www.bloomberg.com/quote/' + @symbol
39
+ match()
40
+ end
41
+ end
42
+
43
+ class ApmexGoldQuoteOnly < QuoteOnly
44
+ def initialize(options)
45
+ super(options)
46
+ @css = 'table.table-spot-prices > tbody > tr:nth-child(1) > td:nth-child(2) > span'
47
+ @url = 'http://www.apmex.com'
48
+ match()
49
+ end
50
+
51
+ def match
52
+ super
53
+ css_text_match = /(\d+\.\d+)/.match(@quote.to_s)
54
+ @quote = css_text_match[1].to_f
55
+ end
56
+ end
57
+
58
+ class ApmexSilverQuoteOnly < QuoteOnly
59
+ def initialize(options)
60
+ super(options)
61
+ @css = 'table.table-spot-prices > tbody > tr:nth-child(2) > td:nth-child(2) > span'
62
+ @url = 'http://www.apmex.com'
63
+ match()
64
+ end
65
+
66
+ def match
67
+ super
68
+ css_text_match = /(\d+\.\d+)/.match(@quote.to_s)
69
+ @quote = css_text_match[1].to_f
70
+ end
71
+ end
@@ -0,0 +1,28 @@
1
+ require 'minitest/autorun'
2
+ require 'quote-only'
3
+
4
+ class QuoteOnlyTest < Minitest::Test
5
+ def test_
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
+
10
+ cnn_market_tests.each do |c|
11
+ f = CnnMarketQuoteOnly.new(c)
12
+ puts f
13
+ assert f.quote.is_a? Float
14
+ end
15
+
16
+ f = BloombergQuoteOnly.new({ :symbol => 'USGG10YR:IND', :friendly_name => '10 Year', :decimal_places => 2 })
17
+ puts f
18
+ assert f.quote.is_a? Float
19
+
20
+ f = ApmexGoldQuoteOnly.new({ :symbol => 'Gold Spot', :friendly_name => 'Gold', :decimal_places => 0 })
21
+ puts f
22
+ assert f.quote.is_a? Float
23
+
24
+ f = ApmexSilverQuoteOnly.new({ :symbol => 'Silver Spot', :friendly_name => 'Silver', :decimal_places => 0 })
25
+ puts f
26
+ assert f.quote.is_a? Float
27
+ end
28
+ end
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: quote-only
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - cscribn
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-21 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Most finincial websites show the daily change of a financial asset, along
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.
18
+ email:
19
+ executables: []
20
+ extensions: []
21
+ extra_rdoc_files: []
22
+ files:
23
+ - lib/quote-only.rb
24
+ - test/test-quote-only.rb
25
+ homepage: http://rubygems.org/gems/quote-only
26
+ licenses:
27
+ - MIT
28
+ metadata: {}
29
+ post_install_message:
30
+ rdoc_options: []
31
+ require_paths:
32
+ - lib
33
+ required_ruby_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ required_rubygems_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ requirements: []
44
+ rubyforge_project:
45
+ rubygems_version: 2.2.3
46
+ signing_key:
47
+ specification_version: 4
48
+ summary: Get only the quote for assets in your portfolio, without daily change.
49
+ test_files: []