oai 1.2.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c0a80559d64aa25add07953e978e93f9abfbc89e03c67bf306e79f0d7b18b0f7
4
- data.tar.gz: 7989ff1c6dec95c3965cb3adc1d0bc156d250b6129002be50193443994d03caf
3
+ metadata.gz: '0739f4d294a977be9445e06f872feb4aa421ecc35c65d4ba4c07af0f48f98070'
4
+ data.tar.gz: b444b8a7f6cfbeccf045e6794b2d6d001dc319fcf362383404735215adcb3cfa
5
5
  SHA512:
6
- metadata.gz: db8b7e74c65625da8b47b35ef23a7e620777dfefb0a6a8d63a6a7314534dbfe46606bf863aef4a839087547280700519f35e3b10bdf10bf70ba93959ae3125e2
7
- data.tar.gz: ad14343ae9a61b6516f7e079db4afc0b7eddbb5e70d8d962221842a5fe4f8b49da63d37dc8eeb7cfe9e163617d4d2a3cae93e37e8943b784df7d0dc1eb1a7cce
6
+ metadata.gz: 0edac39be81e755d256f5f39b0772d8568450e2dd6bc837982ad3568547e8ee46b94c3f17d14e69ad94a1ef95458992f9538108f919a3623b9994a42b11203f5
7
+ data.tar.gz: c182374267d3acf402f9f9a24c3342739f4e3b72fac229076237126444e7aa674acaea7ae8122de71bc7aa9615cfe9a5864fe3ed4e6c31e3a8f848ed27db41aa
data/README.md CHANGED
@@ -125,4 +125,4 @@ That may make changes to appraisal gemfiles that you should commit to repo.
125
125
  License
126
126
  -------
127
127
 
128
- [![CC0 - Public Domain](http://i.creativecommons.org/p/zero/1.0/88x15.png)](http://creativecommons.org/publicdomain/zero/1.0/)
128
+ [MIT](./LICENSE)
@@ -3,8 +3,26 @@ module OAI::Provider::Response
3
3
  def self.inherited(klass)
4
4
  klass.valid_parameters :metadata_prefix, :from, :until, :set
5
5
  klass.default_parameters :metadata_prefix => "oai_dc",
6
- :from => Proc.new {|x| Time.parse(x.provider.model.earliest.to_s) }, #-- OAI 2.0 hack - UTC
7
- :until => Proc.new {|x| Time.parse(x.provider.model.latest.to_s) } #-- OAI 2.0 hack - UTC
6
+ :from => method(:default_from).to_proc,
7
+ :until => method(:default_until).to_proc
8
+ end
9
+
10
+ def self.default_from(response)
11
+ value = Time.parse(response.provider.model.earliest.to_s).utc
12
+ if response.options[:until]
13
+ u = parse_date(response.options[:until])
14
+ value = value.to_date if u.is_a? Date
15
+ end
16
+ value
17
+ end
18
+
19
+ def self.default_until(response)
20
+ value = Time.parse(response.provider.model.latest.to_s).utc
21
+ if response.options[:from]
22
+ f = parse_date(response.options[:from])
23
+ value = value.to_date if f.is_a? Date
24
+ end
25
+ value
8
26
  end
9
27
 
10
28
  # emit record header
@@ -40,6 +40,21 @@ module OAI
40
40
  yield @builder
41
41
  end
42
42
  end
43
+
44
+ protected
45
+
46
+ def self.parse_date(value)
47
+ return value if value.respond_to?(:strftime)
48
+
49
+ if value[-1] == "Z"
50
+ Time.strptime(value, "%Y-%m-%dT%H:%M:%S%Z").utc
51
+ else
52
+ Date.strptime(value, "%Y-%m-%d")
53
+ end
54
+ rescue ArgumentError => e
55
+ raise OAI::ArgumentException.new, "unparsable date: '#{value}'"
56
+ end
57
+
43
58
  private
44
59
 
45
60
  def header
@@ -89,15 +104,7 @@ module OAI
89
104
  end
90
105
 
91
106
  def parse_date(value)
92
- return value if value.respond_to?(:strftime)
93
-
94
- if value[-1] == "Z"
95
- Time.strptime(value, "%Y-%m-%dT%H:%M:%S%Z").utc
96
- else
97
- Date.strptime(value, "%Y-%m-%d")
98
- end
99
- rescue ArgumentError => e
100
- raise OAI::ArgumentException.new, "unparsable date: '#{value}'"
107
+ self.class.parse_date(value)
101
108
  end
102
109
 
103
110
  def internalize(hash = {})
@@ -49,6 +49,22 @@ class TestSimpleProvider < Test::Unit::TestCase
49
49
  assert_equal total, doc.elements['OAI-PMH/ListRecords'].size
50
50
  end
51
51
 
52
+ def test_list_records_with_from_constraints
53
+ assert_nothing_raised { REXML::Document.new(@simple_provider.list_records(:metadata_prefix => 'oai_dc')) }
54
+
55
+ total = @model.find(:all).size
56
+ doc = REXML::Document.new(@simple_provider.list_records(:metadata_prefix => 'oai_dc', from: "2002-10-05"))
57
+ assert_equal total, doc.elements['OAI-PMH/ListRecords'].size
58
+ end
59
+
60
+ def test_list_records_with_until_constraints
61
+ assert_nothing_raised { REXML::Document.new(@simple_provider.list_records(:metadata_prefix => 'oai_dc')) }
62
+
63
+ total = @model.find(:all).size
64
+ doc = REXML::Document.new(@simple_provider.list_records(:metadata_prefix => 'oai_dc', until: "2002-11-05"))
65
+ assert_equal total, doc.elements['OAI-PMH/ListRecords'].size
66
+ end
67
+
52
68
  def test_list_records_with_set_equal_a
53
69
  total = @model.find(:all, :set => 'A').size
54
70
  doc = REXML::Document.new(@simple_provider.list_records(:metadata_prefix => 'oai_dc', :set => 'A'))
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oai
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ed Summers
8
8
  autorequire: oai
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-27 00:00:00.000000000 Z
11
+ date: 2022-04-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: builder