structure 2.0.0.beta → 2.0.0.beta.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 +4 -4
- data/lib/structure.rb +13 -20
- data/lib/structure/version.rb +1 -1
- 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: 29a70d1a2fd15666410907a7868ae65e78ea18d6c6167e7b8142a4eaac35c4e4
|
4
|
+
data.tar.gz: b8cd311d8398866e76b5c776a9f97d2b0dc6c521aba11bbe0d2578993d95c72f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7dfe13a99479e042c55d76db3b5bdb1ab52ca601097f5a0db569328ddfc02f97422a50b123267004c6af7b74711132a4977640a3e846348523b6007b1a1e0052
|
7
|
+
data.tar.gz: 322b7d2757a6135f8fb95ca258d3f607911d4408bd52c3ca1b7f0b319c1bea6f679b565df4758146a2c3b6d3c17882b910b04f9d3e1358921d84f5f21d212d0c
|
data/lib/structure.rb
CHANGED
@@ -3,16 +3,6 @@
|
|
3
3
|
# A tiny library for lazy parsing data with memoized attributes
|
4
4
|
module Structure
|
5
5
|
class << self
|
6
|
-
def serialize(value)
|
7
|
-
if value.respond_to?(:attributes)
|
8
|
-
value.attributes
|
9
|
-
elsif value.is_a?(::Array)
|
10
|
-
value.map { |element| serialize(element) }
|
11
|
-
else
|
12
|
-
value
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
6
|
private
|
17
7
|
|
18
8
|
def included(base)
|
@@ -24,25 +14,28 @@ module Structure
|
|
24
14
|
self.class.attribute_names
|
25
15
|
end
|
26
16
|
|
27
|
-
def
|
28
|
-
attribute_names.
|
29
|
-
hash[key] = ::Structure.serialize(send(key))
|
30
|
-
end
|
17
|
+
def to_a
|
18
|
+
attribute_names.map { |key| [key, send(key)] }
|
31
19
|
end
|
32
20
|
|
33
21
|
def to_h
|
34
|
-
|
22
|
+
Hash[to_a]
|
35
23
|
end
|
36
24
|
|
37
|
-
|
38
|
-
data = attribute_names.map { |key| "#{key}=#{send(key)}" }.join(', ')
|
39
|
-
"#<#{[self.class.name, data].compact.join(' ')}>"
|
40
|
-
end
|
25
|
+
alias attributes to_h
|
41
26
|
|
42
27
|
def inspect
|
43
|
-
to_s
|
28
|
+
detail = if self.class.method_defined?(:to_s, false)
|
29
|
+
to_s
|
30
|
+
else
|
31
|
+
to_a.map { |key, val| "#{key}=#{val.inspect}" }.join(', ')
|
32
|
+
end
|
33
|
+
|
34
|
+
"#<#{self.class.name || '?'} #{detail}>"
|
44
35
|
end
|
45
36
|
|
37
|
+
alias to_s inspect
|
38
|
+
|
46
39
|
def ==(other)
|
47
40
|
attributes == other.attributes
|
48
41
|
end
|
data/lib/structure/version.rb
CHANGED