parsed 0.2.0 → 0.2.1

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: e649af05fed7637c624567a995d7d42065f94037
4
- data.tar.gz: 835ea170f8bcefb50a2504a3dbd0c92844584ad2
3
+ metadata.gz: a31b648e579f02f5a67e76ff13c50c320a41684e
4
+ data.tar.gz: c08072c995a863fcca5798d7582ebe2f0f7ae8b8
5
5
  SHA512:
6
- metadata.gz: 8311ecf1b5363788ea33545a48df968cc2fbc52b79c437396361b306c951730989e949ba284fdf90fab9b12b8953e5eb2039927f64e057baf0ce03bed3ce4c8e
7
- data.tar.gz: 99bbd5c32f951b0ff7123dbe446e6c2c1168de4b64bd00343356e29b9d03e2b5f842fa3cfd265a9cfd5c731c438e13594f850e42519d7872f375a37a8501d7f5
6
+ metadata.gz: 438a84a1c8c5b334c21d40863ca1d530cb1e86ba687a24964f94891c7ca952222c0272dcbeadf210b5cf10e55787596674cbcd166884b4fd01c459ef80468bb6
7
+ data.tar.gz: 6c52e884a17a830ab855cd468a1884635442f0b373adcd798925e86d99d31acb9f2da6a8829f21ee7bf67487327c2ce7fdbfd6a1ef7e66f805a90586eaf61a1b
@@ -71,8 +71,13 @@ module Parsed
71
71
  clazz = determine_collection_class(field)
72
72
  if clazz
73
73
  elements = parseable_json[field.to_sym] || []
74
+
74
75
  elements.map do |element|
75
- clazz.parse(element.to_json)
76
+ if element.instance_of? Hash
77
+ clazz.parse(element.to_json)
78
+ else
79
+ element
80
+ end
76
81
  end
77
82
  else
78
83
  parseable_json[field.to_sym]
@@ -1,3 +1,3 @@
1
1
  module Parsed
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
  end
@@ -2,20 +2,14 @@ require 'spec_helper'
2
2
 
3
3
  class League
4
4
  include Parsed::Parseable
5
-
6
5
  attr_accessor :name, :country, :teams
7
-
8
6
  parses :name, :teams
9
-
10
7
  end
11
8
 
12
9
  class Team
13
10
  include Parsed::Parseable
14
-
15
11
  attr_accessor :name, :city
16
-
17
12
  parses :name, :city
18
-
19
13
  end
20
14
 
21
15
  describe League do
@@ -69,12 +63,12 @@ describe League do
69
63
  end
70
64
 
71
65
  it 'returns an object for each element in the collection' do
72
- subject.teams.size == 2
66
+ subject.teams.size.should == 2
73
67
  end
74
68
 
75
69
  it 'parses parseable objects inside the collection' do
76
- subject.teams.first.name == 'Arsenal'
77
- subject.teams.first.city == 'Swansea City'
70
+ subject.teams.first.name.should == 'Arsenal'
71
+ subject.teams.first.city.should == 'London'
78
72
  end
79
73
 
80
74
  end
@@ -99,6 +93,27 @@ describe League do
99
93
  end
100
94
 
101
95
  end
96
+
97
+ describe 'with primitive elements' do
98
+
99
+ let(:premier_league) do
100
+ <<-EOS
101
+ {
102
+ "name": "Premier League",
103
+ "teams": ["Arsenal", "Swansea City"]
104
+ }
105
+ EOS
106
+ end
107
+
108
+ subject do
109
+ League.parse(premier_league)
110
+ end
111
+
112
+ it 'returns an element for each primitive in the collection' do
113
+ subject.teams.should == ['Arsenal', 'Swansea City']
114
+ end
115
+
116
+ end
102
117
  end
103
118
  end
104
119
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parsed
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robin Roestenburg