nasdaq_query 0.0.1
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.
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +40 -0
- data/Rakefile +14 -0
- data/lib/nasdaq_query.rb +8 -0
- data/lib/nasdaq_query/dividend_history.rb +25 -0
- data/lib/nasdaq_query/version.rb +3 -0
- data/nasdaq_query.gemspec +23 -0
- data/spec/dividend_history_spec.rb +16 -0
- data/spec/spec_helper.rb +9 -0
- metadata +112 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Jim Lindstrom
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# NasdaqQuery
|
2
|
+
|
3
|
+
This gem initially includes just one feature: to look up a company's dividend history. This is useful for calculating a company's beta, which can be computed by a regression that includes, among other factors, a stock's cum-dividend earnings over time.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'nasdaq_query'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install nasdaq_query
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Here's how you'd look up Apple's dividend history:
|
22
|
+
|
23
|
+
require 'nasdaq_query'
|
24
|
+
|
25
|
+
entries = NasdaqQuery::DividendHistory.for_symbol("aapl")
|
26
|
+
entries.length # => 32
|
27
|
+
entries.first # => {:ex_eff_date=>#<Date: 2013-02-07 ((2456331j,0s,0n),+0s,2299161j)>,
|
28
|
+
# :type=>"Cash",
|
29
|
+
# :cash_amt=>2.65,
|
30
|
+
# :declaration_date=>#<Date: 2013-01-23 ((2456316j,0s,0n),+0s,2299161j)>,
|
31
|
+
# :record_date=>#<Date: 2013-02-11 ((2456335j,0s,0n),+0s,2299161j)>,
|
32
|
+
# :payment_date=>#<Date: 2013-02-14 ((2456338j,0s,0n),+0s,2299161j)>}
|
33
|
+
|
34
|
+
## Contributing
|
35
|
+
|
36
|
+
1. Fork it
|
37
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
38
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
39
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
40
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift File.expand_path("#{File.dirname(__FILE__)}/lib")
|
3
|
+
|
4
|
+
require "bundler"
|
5
|
+
Bundler::GemHelper.install_tasks
|
6
|
+
|
7
|
+
require 'rspec'
|
8
|
+
require 'rspec/core/rake_task'
|
9
|
+
|
10
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
11
|
+
t.pattern = 'spec/*_spec.rb'
|
12
|
+
end
|
13
|
+
|
14
|
+
task :default => :spec
|
data/lib/nasdaq_query.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
require 'date'
|
3
|
+
|
4
|
+
module NasdaqQuery
|
5
|
+
class DividendHistory
|
6
|
+
def self.for_symbol(sym)
|
7
|
+
doc = Nokogiri::HTML(`curl -s 'http://www.nasdaq.com/symbol/#{sym.downcase}/dividend-history'`)
|
8
|
+
rows = doc.xpath("//table[@class='dataGrid']/tr")
|
9
|
+
rows.shift # skip the header row
|
10
|
+
entries = rows.map do |row|
|
11
|
+
tds = row.xpath(".//td")
|
12
|
+
{
|
13
|
+
:ex_eff_date => begin; Date.strptime(tds[0].xpath(".//span").text, "%m/%d/%Y"); rescue; nil; end,
|
14
|
+
:type => tds[1].text,
|
15
|
+
:cash_amt => tds[2].xpath(".//span").text.to_f,
|
16
|
+
:declaration_date => begin; Date.strptime(tds[3].xpath(".//span").text, "%m/%d/%Y"); rescue; nil; end,
|
17
|
+
:record_date => begin; Date.strptime(tds[4].xpath(".//span").text, "%m/%d/%Y"); rescue; nil; end,
|
18
|
+
:payment_date => begin; Date.strptime(tds[5].xpath(".//span").text, "%m/%d/%Y"); rescue; nil; end
|
19
|
+
}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'nasdaq_query/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "nasdaq_query"
|
8
|
+
gem.version = NasdaqQuery::VERSION
|
9
|
+
gem.authors = ["Jim Lindstrom"]
|
10
|
+
gem.email = ["jim.lindstrom@gmail.com"]
|
11
|
+
gem.description = %q{Get stock information from Nasdaq.com}
|
12
|
+
gem.summary = %q{Stock info from nasdaq.com}
|
13
|
+
gem.homepage = ""
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_development_dependency 'rake'
|
21
|
+
gem.add_development_dependency 'rspec'
|
22
|
+
gem.add_dependency 'nokogiri'
|
23
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe NasdaqQuery::DividendHistory do
|
4
|
+
describe "#for_symbol" do
|
5
|
+
let(:sym) { "aapl" }
|
6
|
+
subject { NasdaqQuery::DividendHistory.for_symbol(sym) }
|
7
|
+
it { should be_a Array }
|
8
|
+
it "should have the right keys" do
|
9
|
+
expected_keys = [:ex_eff_date, :type, :cash_amt, :declaration_date, :record_date, :payment_date]
|
10
|
+
subject.all?{ |entry| entry.keys == expected_keys }.should be_true
|
11
|
+
end
|
12
|
+
it "should be the right length" do
|
13
|
+
subject.length.should >= 32
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nasdaq_query
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jim Lindstrom
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-08-24 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: nokogiri
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: Get stock information from Nasdaq.com
|
63
|
+
email:
|
64
|
+
- jim.lindstrom@gmail.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- Gemfile
|
71
|
+
- LICENSE.txt
|
72
|
+
- README.md
|
73
|
+
- Rakefile
|
74
|
+
- lib/nasdaq_query.rb
|
75
|
+
- lib/nasdaq_query/dividend_history.rb
|
76
|
+
- lib/nasdaq_query/version.rb
|
77
|
+
- nasdaq_query.gemspec
|
78
|
+
- spec/dividend_history_spec.rb
|
79
|
+
- spec/spec_helper.rb
|
80
|
+
homepage: ''
|
81
|
+
licenses: []
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
88
|
+
requirements:
|
89
|
+
- - ! '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
segments:
|
93
|
+
- 0
|
94
|
+
hash: -868230402829926022
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ! '>='
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
segments:
|
102
|
+
- 0
|
103
|
+
hash: -868230402829926022
|
104
|
+
requirements: []
|
105
|
+
rubyforge_project:
|
106
|
+
rubygems_version: 1.8.24
|
107
|
+
signing_key:
|
108
|
+
specification_version: 3
|
109
|
+
summary: Stock info from nasdaq.com
|
110
|
+
test_files:
|
111
|
+
- spec/dividend_history_spec.rb
|
112
|
+
- spec/spec_helper.rb
|