ahora 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/ahora/representation.rb +7 -6
- data/lib/ahora/version.rb +1 -1
- data/test/ahora/representation_test.rb +12 -0
- data/test/fixtures/employee.xml +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2065c04a39566cbe01bf9b28acfb93ff2aef87b
|
4
|
+
data.tar.gz: 6fc48d900fa2dff9e0c5986e60675cc7f98d2d17
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1244460dfad085989b9b20298d834a831e2d08643d36332c5e69e401edacb3f62f8f84704617351aa4358143ae75481948f6429304e7cf5f27d55d14a82271c5
|
7
|
+
data.tar.gz: 90d2cf1c5220c144a2f9c9c37486c5a242a6b33ee44285b78bf9af7d1fbfd30941ba4bac331d903aa2b05bf59a4c11daa2543eb59d3ea184373108c8f8b0db70
|
data/lib/ahora/representation.rb
CHANGED
@@ -9,11 +9,12 @@ module Ahora
|
|
9
9
|
class Representation < Nibbler
|
10
10
|
present = lambda { |obj| obj && !obj.empty? }
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
12
|
+
STRING_PARSER = lambda { |node| node.content if present.call(node.content) }
|
13
|
+
INTEGER_PARSER = lambda { |node| Integer(node.content) if present.call(node.content) }
|
14
|
+
FLOAT_PARSER = lambda { |node| Float(node.content) if present.call(node.content) }
|
15
|
+
DATE_PARSER = lambda { |node| Date.parse(node.content) if present.call(node.content) }
|
16
|
+
TIME_PARSER = lambda { |node| Time.parse(node.content) if present.call(node.content) }
|
17
|
+
BOOL_PARSER = lambda { |node| node.content.to_s.downcase == 'true' }
|
17
18
|
|
18
19
|
module Definition
|
19
20
|
def element(*)
|
@@ -43,7 +44,7 @@ module Ahora
|
|
43
44
|
end
|
44
45
|
|
45
46
|
def string(*names)
|
46
|
-
attribute(names)
|
47
|
+
attribute(names, STRING_PARSER)
|
47
48
|
end
|
48
49
|
|
49
50
|
def integer(*names)
|
data/lib/ahora/version.rb
CHANGED
@@ -4,6 +4,7 @@ require_relative '../test_helper'
|
|
4
4
|
require_relative '../../lib/ahora/representation'
|
5
5
|
|
6
6
|
class Employee < Ahora::Representation
|
7
|
+
string :first_name, :last_name
|
7
8
|
boolean :is_rockstar, :slacker, :fired
|
8
9
|
float :rating
|
9
10
|
end
|
@@ -45,5 +46,16 @@ describe "float elements" do
|
|
45
46
|
it "parses float elements" do
|
46
47
|
employee.rating.must_equal 7.8
|
47
48
|
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "string elements" do
|
52
|
+
let(:employee) { Employee.parse(fixture('employee').read) }
|
48
53
|
|
54
|
+
it "returns regular strings" do
|
55
|
+
employee.first_name.must_equal 'John'
|
56
|
+
end
|
57
|
+
|
58
|
+
it "returns nil for empty strings" do
|
59
|
+
employee.last_name.must_equal nil
|
60
|
+
end
|
49
61
|
end
|
data/test/fixtures/employee.xml
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ahora
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthijs Langenberg
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-08-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nibbler
|