harrisj-nytimes-articles 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :minor: 1
3
- :patch: 3
2
+ :minor: 2
3
+ :patch: 0
4
4
  :major: 0
@@ -57,7 +57,7 @@ module Nytimes
57
57
  :author => text_field(params['author']),
58
58
  :body => text_field(params['body']),
59
59
  :byline => text_field(params['byline']),
60
- :fee => params['fee'] || false,
60
+ :fee => boolean_field(params['fee']),
61
61
  :lead_paragraph => text_field(params['lead_paragraph']),
62
62
  :nytd_title => text_field(params['nytd_title']),
63
63
  :nytd_lead_paragraph => text_field(params['nytd_lead_paragraph']),
@@ -302,15 +302,11 @@ module Nytimes
302
302
  end
303
303
 
304
304
  def self.facet_argument(name, value, exclude = false)
305
- unless value.is_a? Array
306
- value = [value]
307
- end
308
-
309
305
  if name.is_a? Symbol
310
306
  name = Facet.symbol_name(name)
311
307
  end
312
308
 
313
- "#{'-' if exclude}#{name}:[#{value.join(',')}]"
309
+ "#{'-' if exclude}#{name}:[#{value}]"
314
310
  end
315
311
 
316
312
  def self.parse_facet_params(facets, exclude = false)
@@ -338,11 +334,19 @@ module Nytimes
338
334
  end
339
335
 
340
336
  facet_hash.each_pair do |k,v|
341
- facet_args << facet_argument(k, v, exclude)
337
+ if v.is_a? Array
338
+ facet_args += v.map {|el| facet_argument(k, el, exclude)}
339
+ else
340
+ facet_args << facet_argument(k, v, exclude)
341
+ end
342
342
  end
343
343
  when Hash
344
344
  facets.each_pair do |k,v|
345
- facet_args << facet_argument(k, v, exclude)
345
+ if v.is_a? Array
346
+ facet_args += v.map {|el| facet_argument(k, el, exclude)}
347
+ else
348
+ facet_args << facet_argument(k, v, exclude)
349
+ end
346
350
  end
347
351
  end
348
352
 
@@ -52,6 +52,23 @@ module Nytimes
52
52
  return nil unless value =~ /^\d{8}$/
53
53
  Date.strptime(value, "%Y%m%d")
54
54
  end
55
+
56
+ def self.boolean_field(value)
57
+ case value
58
+ when nil
59
+ false
60
+ when TrueClass
61
+ true
62
+ when FalseClass
63
+ false
64
+ when 'Y'
65
+ true
66
+ when 'N'
67
+ false
68
+ else
69
+ false
70
+ end
71
+ end
55
72
 
56
73
  def self.invoke(params={})
57
74
  begin
@@ -159,7 +159,7 @@ class TestNytimes::TestArticles::TestArticle < Test::Unit::TestCase
159
159
  end
160
160
 
161
161
  should "accept an Facet string hashed to an array terms" do
162
- Article.expects(:invoke).with(has_entry("query", "#{Facet::GEO}:[CALIFORNIA,GREAT BRITAIN]"))
162
+ Article.expects(:invoke).with(has_entry("query", "#{Facet::GEO}:[CALIFORNIA] #{Facet::GEO}:[GREAT BRITAIN]"))
163
163
  Article.search :only_facets => {Facet::GEO => ['CALIFORNIA', 'GREAT BRITAIN']}
164
164
  end
165
165
 
@@ -181,7 +181,7 @@ class TestNytimes::TestArticles::TestArticle < Test::Unit::TestCase
181
181
  f = Facet.new(Facet::GEO, 'CALIFORNIA', 2394)
182
182
  f2 = Facet.new(Facet::GEO, 'IOWA', 12)
183
183
 
184
- Article.expects(:invoke).with(has_entry("query", "#{Facet::GEO}:[CALIFORNIA,IOWA]"))
184
+ Article.expects(:invoke).with(has_entry("query", "#{Facet::GEO}:[CALIFORNIA] #{Facet::GEO}:[IOWA]"))
185
185
  Article.search :only_facets => [f, f2]
186
186
  end
187
187
 
@@ -203,7 +203,7 @@ class TestNytimes::TestArticles::TestArticle < Test::Unit::TestCase
203
203
  end
204
204
 
205
205
  should "accept an Facet string hashed to an array terms" do
206
- Article.expects(:invoke).with(has_entry("query", "-#{Facet::GEO}:[CALIFORNIA,GREAT BRITAIN]"))
206
+ Article.expects(:invoke).with(has_entry("query", "-#{Facet::GEO}:[CALIFORNIA] -#{Facet::GEO}:[GREAT BRITAIN]"))
207
207
  Article.search :except_facets => {Facet::GEO => ['CALIFORNIA', 'GREAT BRITAIN']}
208
208
  end
209
209
 
@@ -225,7 +225,7 @@ class TestNytimes::TestArticles::TestArticle < Test::Unit::TestCase
225
225
  f = Facet.new(Facet::GEO, 'CALIFORNIA', 2394)
226
226
  f2 = Facet.new(Facet::GEO, 'IOWA', 12)
227
227
 
228
- Article.expects(:invoke).with(has_entry("query", "-#{Facet::GEO}:[CALIFORNIA,IOWA]"))
228
+ Article.expects(:invoke).with(has_entry("query", "-#{Facet::GEO}:[CALIFORNIA] -#{Facet::GEO}:[IOWA]"))
229
229
  Article.search :except_facets => [f, f2]
230
230
  end
231
231
 
@@ -488,10 +488,22 @@ class TestNytimes::TestArticles::TestArticle < Test::Unit::TestCase
488
488
  assert_equal false, article.free?
489
489
  end
490
490
 
491
+ should "be true if returned as Y from the API" do
492
+ article = Article.init_from_api('fee' => 'Y')
493
+ assert_equal true, article.fee?
494
+ assert_equal false, article.free?
495
+ end
496
+
491
497
  should "default to false if not specified in the hash" do
492
498
  assert_equal false, @article.fee?
493
499
  assert_equal true, @article.free?
494
500
  end
501
+
502
+ should "default to false if returned as N from the API" do
503
+ article = Article.init_from_api('fee' => 'N')
504
+ assert_equal false, article.fee?
505
+ assert_equal true, article.free?
506
+ end
495
507
  end
496
508
 
497
509
  context "@url" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: harrisj-nytimes-articles
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jacob Harris
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-02-23 00:00:00 -08:00
12
+ date: 2009-02-27 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency