aston 0.2.0 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eebe5f2b036ff05e61f6e1b09233577fa2494c928c5a50ed21a6392c49e000dd
4
- data.tar.gz: 60d363e3a4047ead68e7af6b16b6a7d05d9419d6918622d1c5e54b15426b8928
3
+ metadata.gz: 898e3930d3a793484b1f1e3be4aa29afdb3d2546960d789e9c392974c94d95e4
4
+ data.tar.gz: 5c98aaf1ef170225d16821338ff4a202e24aa3756aee349fba29093aad8955f5
5
5
  SHA512:
6
- metadata.gz: 0f20ae2f4e61ac774706b0c8ac136e14606485f68877817cbddfb2e27a4bd4e1a961fd898989e269dccf4313c7df0ab01d330ec0ff688938a60f6530bd6846c4
7
- data.tar.gz: 14ba62157897f974353b9f7fc198213bdc4dd285718f77470f7cc0d0f261ce6e3b748f644d522b8a339d11983c4b3081d693b0ee1464ea9a2197da3ed2137f52
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.0)
4
+ aston (0.2.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/aston.gemspec CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
12
12
  spec.description = 'Hash/JSON is not isomorphic to XML, unless produced with this library'
13
13
  spec.homepage = 'https://github.com/am-kantox/aston'
14
14
  spec.license = 'MIT'
15
- spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
15
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.2.0')
16
16
 
17
17
  spec.metadata['allowed_push_host'] = 'https://rubygems.org'
18
18
 
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.0'
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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aston
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aleksei Matiushkin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-02-08 00:00:00.000000000 Z
11
+ date: 2024-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: prop_check
@@ -76,7 +76,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
76
76
  requirements:
77
77
  - - ">="
78
78
  - !ruby/object:Gem::Version
79
- version: 2.3.0
79
+ version: 2.2.0
80
80
  required_rubygems_version: !ruby/object:Gem::Requirement
81
81
  requirements:
82
82
  - - ">="