xml_mapper 0.5.4 → 0.5.5
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/xml_mapper.rb +7 -3
- data/spec/xml_mapper_spec.rb +11 -14
- data/xml_mapper.gemspec +2 -2
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.5
|
data/lib/xml_mapper.rb
CHANGED
@@ -212,12 +212,16 @@ class XmlMapper
|
|
212
212
|
def parse_duration(string)
|
213
213
|
return string.to_i if string.match(/^\d+$/)
|
214
214
|
string = "00:#{string}" if string.match(/^(\d+):(\d+)$/)
|
215
|
-
string = string.to_s.gsub(/PT(\d+M.*)/,"PT0H\\1")
|
216
|
-
|
217
|
-
|
215
|
+
string = string.to_s.gsub(/PT(\d+M.*)/,"PT0H\\1") # insert 0H into PT3M12S, for example: PT0H3M12S
|
216
|
+
if string.match(/^PT(\d+)H(\d+)M(\d+)S$/) || string.match(/^(\d+):(\d+):(\d+)$/)
|
217
|
+
$1.to_i * 3600 + $2.to_i * 60 + $3.to_i
|
218
|
+
else
|
219
|
+
nil
|
220
|
+
end
|
218
221
|
end
|
219
222
|
|
220
223
|
def parse_date(text)
|
221
224
|
text.to_s.strip.length > 0 ? Date.parse(text.to_s.strip) : nil
|
225
|
+
rescue
|
222
226
|
end
|
223
227
|
end
|
data/spec/xml_mapper_spec.rb
CHANGED
@@ -16,20 +16,13 @@ describe "XmlMapper" do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
describe "#parse_duration" do
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
it "should convert iso string to lengths" do
|
27
|
-
XmlMapper.new.parse_duration("PT0H5M54S").should == 354
|
28
|
-
XmlMapper.new.parse_duration("PT3M12S").should == 192
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should not convert integer values" do
|
32
|
-
XmlMapper.new.parse_duration("60").should == 60
|
19
|
+
{
|
20
|
+
"60" => 60, "no_duration" => nil, "PT0H5M54S" => 354, "PT3M12S" => 192, "PT64M54S" => 3894,
|
21
|
+
"00:01" => 1, "00:00:01" => 1, "00:01:01" => 61, "01:01:01" => 3661
|
22
|
+
}.each do |duration_string, value|
|
23
|
+
it "converts #{duration_string.inspect} to #{value}" do
|
24
|
+
XmlMapper.new.parse_duration(duration_string).should == value
|
25
|
+
end
|
33
26
|
end
|
34
27
|
end
|
35
28
|
|
@@ -45,6 +38,10 @@ describe "XmlMapper" do
|
|
45
38
|
it "parses dates correctly" do
|
46
39
|
XmlMapper.new.parse_date("2010-09-01").should == Date.new(2010, 9, 1)
|
47
40
|
end
|
41
|
+
|
42
|
+
it "returns nil when unable to parse date" do
|
43
|
+
XmlMapper.new.parse_date("something_wrong").should be_nil
|
44
|
+
end
|
48
45
|
end
|
49
46
|
|
50
47
|
describe "#add_mapping" do
|
data/xml_mapper.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{xml_mapper}
|
8
|
-
s.version = "0.5.
|
8
|
+
s.version = "0.5.5"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Tobias Schwab"]
|
12
|
-
s.date = %q{2011-04-
|
12
|
+
s.date = %q{2011-04-12}
|
13
13
|
s.description = %q{Declarative XML to Ruby mapping}
|
14
14
|
s.email = %q{tobias.schwab@dynport.de}
|
15
15
|
s.extra_rdoc_files = [
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xml_mapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 1
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 5
|
9
|
-
-
|
10
|
-
version: 0.5.
|
9
|
+
- 5
|
10
|
+
version: 0.5.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Tobias Schwab
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-04-
|
18
|
+
date: 2011-04-12 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|