aston 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/aston/version.rb +1 -1
- data/lib/aston.rb +19 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 898e3930d3a793484b1f1e3be4aa29afdb3d2546960d789e9c392974c94d95e4
|
4
|
+
data.tar.gz: 5c98aaf1ef170225d16821338ff4a202e24aa3756aee349fba29093aad8955f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 89af00e252131a62028dbb616f9d78f91ebd78f4634e9bc35dacdd44840795c237ea8283107798c9972650d7c0e5a66c073bede33bdf8eba91337a4a863f80d4
|
7
|
+
data.tar.gz: ef67c43380668266c68f64d38e43e58d883090bd8fbc048abb3d9216143728c26a23ce4f2bd137f7ff133618468017c7f9ddef74dba33153f011e1120955b6da
|
data/Gemfile.lock
CHANGED
data/lib/aston/version.rb
CHANGED
data/lib/aston.rb
CHANGED
@@ -14,6 +14,10 @@ class Aston
|
|
14
14
|
@data = data
|
15
15
|
end
|
16
16
|
|
17
|
+
def to_hash
|
18
|
+
@data
|
19
|
+
end
|
20
|
+
|
17
21
|
def [](key)
|
18
22
|
@data[key]
|
19
23
|
end
|
@@ -91,7 +95,7 @@ class Aston
|
|
91
95
|
end
|
92
96
|
|
93
97
|
def <<(value)
|
94
|
-
@content << value
|
98
|
+
tap { @content << value }
|
95
99
|
end
|
96
100
|
|
97
101
|
def ==(other)
|
@@ -104,8 +108,21 @@ class Aston
|
|
104
108
|
[comment, opening, *@content, "</#{name}>"].join("\n")
|
105
109
|
end
|
106
110
|
|
111
|
+
def to_hash(remove_empty: false)
|
112
|
+
{
|
113
|
+
name: @name,
|
114
|
+
attributes: @attributes.to_hash,
|
115
|
+
content: @content.data.map { |e| e.is_a?(Aston) ? e.to_hash(remove_empty: remove_empty) : e }
|
116
|
+
}.tap do |hash|
|
117
|
+
if remove_empty
|
118
|
+
hash.delete(:attributes) if hash[:attributes] == {}
|
119
|
+
hash.delete(:content) if hash[:content] == []
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
107
124
|
def to_json(opts = nil)
|
108
|
-
|
125
|
+
to_hash.to_json(opts)
|
109
126
|
end
|
110
127
|
|
111
128
|
def self.parse_hash(hash)
|