square-circle-triangle-yahoo_stock 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Square Circle Triangle
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,7 @@
1
+ = yahoo_stock
2
+
3
+ Description goes here.
4
+
5
+ == Copyright
6
+
7
+ Copyright (c) 2009 Square Circle Triangle. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,49 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "yahoo_stock"
8
+ gem.summary = "Fetches stock data from Yahoo Australia"
9
+ gem.email = "sct@sct.com.au"
10
+ gem.homepage = "http://github.com/square-circle-triangle/yahoo_stock"
11
+ gem.authors = ["Square Circle Triangle"]
12
+ gem.add_dependency "hpricot"
13
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
14
+ end
15
+
16
+ rescue LoadError
17
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
18
+ end
19
+
20
+ require 'spec/rake/spectask'
21
+ Spec::Rake::SpecTask.new(:spec) do |spec|
22
+ spec.libs << 'lib' << 'spec'
23
+ spec.spec_files = FileList['spec/**/*_spec.rb']
24
+ end
25
+
26
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
27
+ spec.libs << 'lib' << 'spec'
28
+ spec.pattern = 'spec/**/*_spec.rb'
29
+ spec.rcov = true
30
+ end
31
+
32
+
33
+ task :default => :spec
34
+
35
+ require 'rake/rdoctask'
36
+ Rake::RDocTask.new do |rdoc|
37
+ if File.exist?('VERSION.yml')
38
+ config = YAML.load(File.read('VERSION.yml'))
39
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
40
+ else
41
+ version = ""
42
+ end
43
+
44
+ rdoc.rdoc_dir = 'rdoc'
45
+ rdoc.title = "yahoo_stock #{version}"
46
+ rdoc.rdoc_files.include('README*')
47
+ rdoc.rdoc_files.include('lib/**/*.rb')
48
+ end
49
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.3
@@ -0,0 +1,16 @@
1
+ require 'rubygems'
2
+ require 'hpricot'
3
+ require 'open-uri'
4
+
5
+ # We're only going to access price right now
6
+ # additional properties can be mapped with a simple
7
+ # method and selector change.
8
+
9
+ module Yahoo
10
+ class Stock
11
+ BASE_URI = 'http://au.finance.yahoo.com/q?s='
12
+ end
13
+ end
14
+
15
+ # Classes
16
+ %w(query base).each{|r| require(File.join(File.dirname(__FILE__), File.basename(__FILE__, '.rb'), r))}
@@ -0,0 +1,42 @@
1
+ module Yahoo
2
+ class Stock
3
+ attr_reader :code
4
+
5
+ def initialize(stock_code)
6
+ @code = stock_code
7
+ end
8
+
9
+ def last_trade_price
10
+ sprintf "%0.2f", get_info.at(".yfnc_tabledata1").inner_text.to_f
11
+ end
12
+
13
+ def last_trade_time_new
14
+ # 'close of trade' if time not present
15
+ t = Time.parse last_trade_time
16
+ if [t.hour, t.min, t.sec] == [0,0,0]
17
+ 'close of trade'
18
+ else
19
+ "#{t.hour}:#{t.min}"
20
+ end
21
+ end
22
+
23
+ def last_trade_date
24
+ t = Time.parse last_trade_time
25
+ t.strftime "%d %B %Y"
26
+ end
27
+
28
+ # Deprecated methods
29
+ def last_trade
30
+ get_info.at(".yfnc_tabledata1").inner_text
31
+ end
32
+
33
+ def last_trade_time
34
+ get_info.search(".yfnc_tabledata1")[1].inner_text
35
+ end
36
+
37
+ private
38
+ def get_info
39
+ @get_info ||= Query.new(BASE_URI + @code).execute
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,15 @@
1
+ module Yahoo #:nodoc
2
+ class Stock
3
+ class Query
4
+ attr_accessor :uri
5
+
6
+ def initialize(uri)
7
+ @uri = uri
8
+ end
9
+
10
+ def execute
11
+ Hpricot(open(@uri).read)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec'
2
+
3
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
4
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
+ require 'yahoo_stock'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
@@ -0,0 +1,4 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "YahooStock" do
4
+ end
@@ -0,0 +1,51 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{yahoo_stock}
5
+ s.version = "0.1.3"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Square Circle Triangle"]
9
+ s.date = %q{2009-07-03}
10
+ s.email = %q{sct@sct.com.au}
11
+ s.extra_rdoc_files = [
12
+ "LICENSE",
13
+ "README.rdoc"
14
+ ]
15
+ s.files = [
16
+ ".document",
17
+ ".gitignore",
18
+ "LICENSE",
19
+ "README.rdoc",
20
+ "Rakefile",
21
+ "VERSION",
22
+ "lib/yahoo_stock.rb",
23
+ "lib/yahoo_stock/base.rb",
24
+ "lib/yahoo_stock/query.rb",
25
+ "spec/spec_helper.rb",
26
+ "spec/yahoo_stock_spec.rb",
27
+ "yahoo_stock.gemspec"
28
+ ]
29
+ s.homepage = %q{http://github.com/square-circle-triangle/yahoo_stock}
30
+ s.rdoc_options = ["--charset=UTF-8"]
31
+ s.require_paths = ["lib"]
32
+ s.rubygems_version = %q{1.3.3}
33
+ s.summary = %q{Fetches stock data from Yahoo Australia}
34
+ s.test_files = [
35
+ "spec/spec_helper.rb",
36
+ "spec/yahoo_stock_spec.rb"
37
+ ]
38
+
39
+ if s.respond_to? :specification_version then
40
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
41
+ s.specification_version = 3
42
+
43
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
44
+ s.add_runtime_dependency(%q<hpricot>, [">= 0"])
45
+ else
46
+ s.add_dependency(%q<hpricot>, [">= 0"])
47
+ end
48
+ else
49
+ s.add_dependency(%q<hpricot>, [">= 0"])
50
+ end
51
+ end
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: square-circle-triangle-yahoo_stock
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - Square Circle Triangle
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-07-03 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hpricot
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description:
26
+ email: sct@sct.com.au
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README.rdoc
34
+ files:
35
+ - .document
36
+ - .gitignore
37
+ - LICENSE
38
+ - README.rdoc
39
+ - Rakefile
40
+ - VERSION
41
+ - lib/yahoo_stock.rb
42
+ - lib/yahoo_stock/base.rb
43
+ - lib/yahoo_stock/query.rb
44
+ - spec/spec_helper.rb
45
+ - spec/yahoo_stock_spec.rb
46
+ - yahoo_stock.gemspec
47
+ has_rdoc: false
48
+ homepage: http://github.com/square-circle-triangle/yahoo_stock
49
+ post_install_message:
50
+ rdoc_options:
51
+ - --charset=UTF-8
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "0"
59
+ version:
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: "0"
65
+ version:
66
+ requirements: []
67
+
68
+ rubyforge_project:
69
+ rubygems_version: 1.2.0
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: Fetches stock data from Yahoo Australia
73
+ test_files:
74
+ - spec/spec_helper.rb
75
+ - spec/yahoo_stock_spec.rb