yahoo_quote 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,9 +2,13 @@ module YahooQuote
2
2
  class Configuration
3
3
 
4
4
  def self.cache_dir=(path)
5
- dir = path.to_s
6
- Dir.mkdir(dir) unless dir.empty? || File.directory?(dir)
7
- @@cache_dir = dir
5
+ if !path
6
+ @@cache_dir = path
7
+ else
8
+ dir = path.to_s
9
+ Dir.mkdir(dir) unless dir.empty? || File.directory?(dir)
10
+ @@cache_dir = dir
11
+ end
8
12
  end
9
13
 
10
14
  def self.cache_dir
@@ -1,3 +1,3 @@
1
1
  module YahooQuote
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/yahoo_quote.rb CHANGED
@@ -42,7 +42,12 @@ module YahooQuote
42
42
  end
43
43
 
44
44
  def filename_quote
45
- YahooQuote::Configuration.cache_dir + "/#{@symbol}.csv"
45
+ File.join(YahooQuote::Configuration.cache_dir, "#{@symbol}.csv")
46
+ end
47
+
48
+ def clear_cache
49
+ Dir.glob(File.join(YahooQuote::Configuration.cache_dir, '*.csv')).each {|f|
50
+ File.unlink f }
46
51
  end
47
52
 
48
53
  def quote_url
@@ -1,5 +1,3 @@
1
- $LOAD_PATH << File.join(File.dirname(__FILE__), '../lib')
2
-
3
1
  require 'yahoo_quote'
4
2
  require 'minitest/autorun'
5
3
  require 'fakeweb'
@@ -12,8 +10,7 @@ class TestYahooQuote < MiniTest::Unit::TestCase
12
10
  FakeWeb.allow_net_connect = false
13
11
  FakeWeb.register_uri(:get, @url_regexp, :response => File.read("test/fakeweb/aapl_good.csv"))
14
12
 
15
- # TODO make gem method to clear the cache
16
- `rm -f /tmp/*csv`
13
+ @cache_dir = File.join('test', 'cache')
17
14
  end
18
15
 
19
16
  def test_empty_arguments
@@ -52,9 +49,9 @@ class TestYahooQuote < MiniTest::Unit::TestCase
52
49
  end
53
50
 
54
51
  def test_get_quote_from_cache
55
- YahooQuote::Configuration.cache_dir = "test/cache"
52
+ YahooQuote::Configuration.cache_dir = @cache_dir
56
53
  quote = YahooQuote::Quote.new('AAPL', ['Name', 'Last Trade (Price Only)', 'P/E Ratio'])
57
- assert File.file? "test/cache/AAPL.csv"
54
+ assert File.file? File.join(@cache_dir, 'AAPL.csv')
58
55
  assert_equal "Apple Inc.", quote.data["Name"]
59
56
  assert_equal 503.65, quote.data["Last Trade (Price Only)"]
60
57
  bad_response = File.read('test/fakeweb/aapl_bad.csv')
@@ -63,6 +60,20 @@ class TestYahooQuote < MiniTest::Unit::TestCase
63
60
  cached_quote = YahooQuote::Quote.new('AAPL', ['Name', 'Last Trade (Price Only)', 'P/E Ratio'])
64
61
  assert_equal "Apple Inc.", cached_quote.data["Name"]
65
62
  assert_equal 503.65, cached_quote.data["Last Trade (Price Only)"]
63
+ # We don't want to cache responses for other tests
64
+ YahooQuote::Configuration.cache_dir = nil
65
+ assert !quote.cache_response?
66
+ assert !cached_quote.cache_response?
67
+ end
68
+
69
+ def test_clear_cache
70
+ YahooQuote::Configuration.cache_dir = @cache_dir
71
+ quote = YahooQuote::Quote.new('AAPL', ['Name'])
72
+ assert Dir.glob(File.join(@cache_dir, '*.csv')).size > 0, 'No files stored in cache'
73
+ quote.clear_cache
74
+ assert_equal 0, Dir.glob(File.join(@cache_dir, '*.csv')).size
75
+ # We don't want to cache responses for other tests
66
76
  YahooQuote::Configuration.cache_dir = nil
77
+ assert !quote.cache_response?
67
78
  end
68
79
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yahoo_quote
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-20 00:00:00.000000000Z
12
+ date: 2012-02-21 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fakeweb
16
- requirement: &2157583180 !ruby/object:Gem::Requirement
16
+ requirement: &2153217660 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *2157583180
24
+ version_requirements: *2153217660
25
25
  description: Easy interaction with Yahoo Finance API
26
26
  email:
27
27
  - bcarreno@yahoo.com