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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1cb06d2658dbbeb7b3ef608c0a075f6bf231a841
4
- data.tar.gz: 70f9af7383998d3f989e2403d4576a1a087cb92d
3
+ metadata.gz: c2065c04a39566cbe01bf9b28acfb93ff2aef87b
4
+ data.tar.gz: 6fc48d900fa2dff9e0c5986e60675cc7f98d2d17
5
5
  SHA512:
6
- metadata.gz: 790ee4e933c2fa58e003f4ab6cf982680da6df0f6ba8861fa9749158cda98a7d10b0b1c51b07748601969c9f2efda1b85baaef154ca7685c9093033a8b388bbd
7
- data.tar.gz: 3348a8dc3dc622b57521061cfbb219c8a2559b27f9456dd477297390df787a9c51ad59339cad49b732fd3386b8b5e1fe0531169115779d1f204ab684b5f4c6d3
6
+ metadata.gz: 1244460dfad085989b9b20298d834a831e2d08643d36332c5e69e401edacb3f62f8f84704617351aa4358143ae75481948f6429304e7cf5f27d55d14a82271c5
7
+ data.tar.gz: 90d2cf1c5220c144a2f9c9c37486c5a242a6b33ee44285b78bf9af7d1fbfd30941ba4bac331d903aa2b05bf59a4c11daa2543eb59d3ea184373108c8f8b0db70
@@ -9,11 +9,12 @@ module Ahora
9
9
  class Representation < Nibbler
10
10
  present = lambda { |obj| obj && !obj.empty? }
11
11
 
12
- INTEGER_PARSER = lambda { |node| Integer(node.content) if present.call(node.content) }
13
- FLOAT_PARSER = lambda { |node| Float(node.content) if present.call(node.content) }
14
- DATE_PARSER = lambda { |node| Date.parse(node.content) if present.call(node.content) }
15
- TIME_PARSER = lambda { |node| Time.parse(node.content) if present.call(node.content) }
16
- BOOL_PARSER = lambda { |node| node.content.to_s.downcase == 'true' }
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
@@ -1,3 +1,3 @@
1
1
  module Ahora
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -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
@@ -1,6 +1,7 @@
1
1
  <?xml version="1.0"?>
2
2
  <employee>
3
3
  <first_name>John</first_name>
4
+ <last_name />
4
5
  <is_rockstar>true</is_rockstar>
5
6
  <slacker>false</slacker>
6
7
  <rating>7.8</rating>
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.1.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-07-26 00:00:00.000000000 Z
11
+ date: 2013-08-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nibbler