class Staticpress::JSObject
Public Class Methods
new(hash = {})
click to toggle source
Calls superclass method
# 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
Protected Class Methods
converter(value, from_class, &block)
click to toggle source
# File lib/staticpress/js_object.rb, line 43 def self.converter(value, from_class, &block) if value.is_a? Array value.map { |vv| converter vv, from_class, &block } elsif value.is_a? from_class block.call value else value end end
Public Instance Methods
-(other)
click to toggle source
# 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)
click to toggle source
# File lib/staticpress/js_object.rb, line 13 def [](key) method_missing key.to_s.to_sym end
merge(other)
click to toggle source
# File lib/staticpress/js_object.rb, line 17 def merge(other) self.class.new to_hash.merge(other.to_hash) end
to_hash()
click to toggle source
# 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