Skip to content

Commit 4efba69

Browse files
committed
Fixes for reported date bug, and new version of libxml(0.5.2.0)
1 parent 3d1e28d commit 4efba69

20 files changed

Lines changed: 182 additions & 134 deletions

Rakefile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ spec = Gem::Specification.new do |s|
2525
s.bindir = 'bin'
2626
s.executables = 'oai'
2727

28-
s.add_dependency('activesupport', '>=1.3.1')
29-
s.add_dependency('chronic', '>=0.0.3')
3028
s.add_dependency('builder', '>=2.0.0')
3129

3230
s.files = %w(README Rakefile) +

lib/oai/client.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,10 @@ def build_uri(verb, opts)
176176

177177
def encode(value)
178178
return CGI.escape(value) unless value.respond_to?(:strftime)
179-
if value.respond_to?(:to_time) # Usually a DateTime or Time
180-
value.to_time.utc.xmlschema
179+
if value.kind_of?(DateTime)
180+
Time.parse(value.asctime).utc.xmlschema
181+
elsif value.kind_of?(Time)
182+
value.utc.xmlschema
181183
else # Assume something date like
182184
value.strftime('%Y-%m-%d')
183185
end
@@ -272,12 +274,10 @@ def externalize(value)
272274
def parse_date(value)
273275
return value if value.respond_to?(:strftime)
274276

275-
# Oddly Chronic doesn't parse an UTC encoded datetime.
276-
# Luckily Time does
277-
dt = Chronic.parse(value) || Time.parse(value)
278-
raise OAI::ArgumentError.new unless dt
279-
280-
dt.utc
277+
Date.parse(value) # This will raise an exception for badly formatted dates
278+
Time.parse(value).utc # Sadly, this will not
279+
rescue
280+
raise OAI::ArgumentError.new
281281
end
282282

283283
# Strip out invalid UTF-8 characters. Regex from the W3C, inverted.

lib/oai/harvester/harvest.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def call(url, opts)
107107
end
108108

109109
def get_records(doc)
110-
doc.doc.root.elements.to_a("/OAI-PMH/ListRecords/record")
110+
doc.find("/OAI-PMH/ListRecords/record").to_a
111111
end
112112

113113
def build_options_hash(site)

lib/oai/provider.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
require 'active_support'
1+
require 'rexml/document'
2+
require 'singleton'
23
require 'builder'
3-
require 'chronic'
44

55
if not defined?(OAI::Const::VERBS)
66
require 'oai/exception'
@@ -266,8 +266,8 @@ def get_record(options = {})
266266
Response::GetRecord.new(self.class, options).to_xml
267267
end
268268

269-
# xml_response = process_verb('ListRecords', :from => 'October',
270-
# :until => 'November') # thanks Chronic!
269+
# xml_response = process_verb('ListRecords', :from => 'October 1, 2005',
270+
# :until => 'November 1, 2005')
271271
#
272272
# If you are implementing a web interface using process_request is the
273273
# preferred way.

lib/oai/provider/metadata_format.rb

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'singleton'
2+
13
module OAI::Provider::Metadata
24
# == Metadata Base Class
35
#
@@ -55,8 +57,8 @@ def value_for(field, record, map)
5557
method = map[field] ? map[field].to_s : field.to_s
5658

5759
methods = record.public_methods(false)
58-
if methods.include?(method.pluralize)
59-
record.send method.pluralize
60+
if methods.include?(pluralize(method))
61+
record.send pluralize(method)
6062
elsif methods.include?(method)
6163
record.send method
6264
else
@@ -68,6 +70,46 @@ def value_for(field, record, map)
6870
def header_specification
6971
raise NotImplementedError.new
7072
end
73+
74+
# Shamelessly lifted form ActiveSupport. Thanks Rails community!
75+
def pluralize(word)
76+
# Use ActiveSupports pluralization if it's available.
77+
return word.pluralize if word.respond_to?(:pluralize)
78+
79+
# Otherwise use our own simple pluralization rules.
80+
result = word.to_s.dup
81+
82+
# Uncountable words
83+
return result if %w(equipment information rice money species series fish sheep).include?(result)
84+
85+
# Irregular words
86+
{ 'person' => 'people', 'man' => 'men', 'child' => 'children', 'sex' => 'sexes',
87+
'move' => 'moves', 'cow' => 'kine' }.each { |k,v| return v if word == k }
88+
89+
rules.each { |(rule, replacement)| break if result.gsub!(rule, replacement) }
90+
end
91+
92+
def rules
93+
[
94+
[/$/, 's'],
95+
[/s$/i, 's'],
96+
[/(ax|test)is$/i, '\1es'],
97+
[/(octop|vir)us$/i, '\1i'],
98+
[/(alias|status)$/i, '\1es'],
99+
[/(bu)s$/i, '\1ses'],
100+
[/(buffal|tomat)o$/i, '\1oes'],
101+
[/([ti])um$/i, '\1a'],
102+
[/sis$/i, 'ses'],
103+
[/(?:([^f])fe|([lr])f)$/i, '\1\2ves'],
104+
[/(hive)$/i, '\1s'],
105+
[/([^aeiouy]|qu)y$/i, '\1ies'],
106+
[/(x|ch|ss|sh)$/i, '\1es'],
107+
[/(matr|vert|ind)(?:ix|ex)$/i, '\1ices'],
108+
[/([m|l])ouse$/i, '\1ice'],
109+
[/^(ox)$/i, '\1en'],
110+
[/(quiz)$/i, '\1zes']
111+
]
112+
end
71113

72114
end
73115

lib/oai/provider/model/activerecord_caching_wrapper.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ def select_partial(token)
103103
end
104104

105105
oaitoken = OaiToken.find_by_token(token.to_s)
106-
107106
raise ResumptionTokenException.new unless oaitoken
108107

109108
PartialResult.new(

lib/oai/provider/model/activerecord_wrapper.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ def initialize(model, options={})
2020
@limit = options.delete(:limit)
2121

2222
unless options.empty?
23-
raise ArgumentException.new(
24-
"Unsupported options [#{options.join(', ')}]"
23+
raise ArgumentError.new(
24+
"Unsupported options [#{options.keys.join(', ')}]"
2525
)
2626
end
2727
end

lib/oai/provider/response.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,10 @@ def externalize(value)
9494
def parse_date(value)
9595
return value if value.respond_to?(:strftime)
9696

97-
# Oddly Chronic doesn't parse an UTC encoded datetime.
98-
# Luckily Time does
99-
dt = Chronic.parse(value) || Time.parse(value)
100-
raise OAI::ArgumentError.new unless dt
101-
102-
dt.utc
97+
Date.parse(value) # This will raise an exception for badly formatted dates
98+
Time.parse(value).utc # Sadly, this will not
99+
rescue
100+
raise OAI::ArgumentError.new
103101
end
104102

105103
def internalize(hash = {})

lib/oai/xpath.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module XPath
55
def xpath_all(doc, path)
66
case parser_type(doc)
77
when 'libxml'
8-
return doc.find(path)
8+
return doc.find(path).to_a if doc.find(path)
99
when 'rexml'
1010
return REXML::XPath.match(doc, path)
1111
end
1 KB
Binary file not shown.

0 commit comments

Comments
 (0)