Class: Staticpress::JSObject
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- Staticpress::JSObject
show all
- Defined in:
- lib/staticpress/js_object.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.new(hash = {}) ⇒ Object
31
32
33
34
35
36
37
38
39
|
# File 'lib/staticpress/js_object.rb', line 31
def self.new(hash = {})
converted = {}
hash.each do |key, value|
converted[key] = converter(value, Hash) { |v| new v }
end
super converted
end
|
Instance Method Details
#-(other) ⇒ Object
5
6
7
8
9
10
11
|
# File 'lib/staticpress/js_object.rb', line 5
def -(other)
other_hash = other.to_hash
difference = to_hash.select do |key, value|
value != other_hash[key]
end
self.class.new difference
end
|
#[](key) ⇒ Object
13
14
15
|
# File 'lib/staticpress/js_object.rb', line 13
def [](key)
method_missing key.to_s.to_sym
end
|
#merge(other) ⇒ Object
17
18
19
|
# File 'lib/staticpress/js_object.rb', line 17
def merge(other)
self.class.new to_hash.merge(other.to_hash)
end
|
#to_hash ⇒ Object
21
22
23
24
25
26
27
28
29
|
# File 'lib/staticpress/js_object.rb', line 21
def to_hash
converted = {}
@table.each do |key, value|
converted[key] = self.class.converter(value, JSObject) { |v| v.to_hash }
end
converted
end
|