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 +4 -4
- data/lib/parsed/parseable.rb +6 -1
- data/lib/parsed/version.rb +1 -1
- data/spec/parsing_regular_classes_spec.rb +24 -9
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a31b648e579f02f5a67e76ff13c50c320a41684e
|
4
|
+
data.tar.gz: c08072c995a863fcca5798d7582ebe2f0f7ae8b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 438a84a1c8c5b334c21d40863ca1d530cb1e86ba687a24964f94891c7ca952222c0272dcbeadf210b5cf10e55787596674cbcd166884b4fd01c459ef80468bb6
|
7
|
+
data.tar.gz: 6c52e884a17a830ab855cd468a1884635442f0b373adcd798925e86d99d31acb9f2da6a8829f21ee7bf67487327c2ce7fdbfd6a1ef7e66f805a90586eaf61a1b
|
data/lib/parsed/parseable.rb
CHANGED
@@ -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
|
-
|
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]
|
data/lib/parsed/version.rb
CHANGED
@@ -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 == '
|
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
|