aston 0.2.1 → 0.2.2

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
  SHA256:
3
- metadata.gz: a5d6c92882bb30176c07f1b779967375db94e1113921625ccb4d7fb1ce3188ac
4
- data.tar.gz: f610991695447768793e84f01d5df61f9c5d212bbc2e7ae3a12e7c3a692dd076
3
+ metadata.gz: 898e3930d3a793484b1f1e3be4aa29afdb3d2546960d789e9c392974c94d95e4
4
+ data.tar.gz: 5c98aaf1ef170225d16821338ff4a202e24aa3756aee349fba29093aad8955f5
5
5
  SHA512:
6
- metadata.gz: e786163d8153cd6ef95120ac93cbbf0e6369830d95c0cc023bbb05faff63100e8507af00b2eb5bd56e4cd6c47f7a0828a890f84f928c996270e8a705377f06b5
7
- data.tar.gz: 2cd43defb89caea7e65a8f35ad33b3c87685511b5bee2acaf8863b51db7b48f569e87fcd0fc1d4b35f07f4d0476f623e5418389cbcd2ab937c8e600ad15b0b62
6
+ metadata.gz: 89af00e252131a62028dbb616f9d78f91ebd78f4634e9bc35dacdd44840795c237ea8283107798c9972650d7c0e5a66c073bede33bdf8eba91337a4a863f80d4
7
+ data.tar.gz: ef67c43380668266c68f64d38e43e58d883090bd8fbc048abb3d9216143728c26a23ce4f2bd137f7ff133618468017c7f9ddef74dba33153f011e1120955b6da
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- aston (0.2.1)
4
+ aston (0.2.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/lib/aston/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Aston
4
- VERSION = '0.2.1'
4
+ VERSION = '0.2.2'
5
5
  end
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
- { name: @name, attributes: @attributes, content: @content }.to_json(opts)
125
+ to_hash.to_json(opts)
109
126
  end
110
127
 
111
128
  def self.parse_hash(hash)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aston
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aleksei Matiushkin