Module: JsonToOpenStruct
- Defined in:
- lib/json_to_openstruct.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(host_class) ⇒ Object
6 7 8 |
# File 'lib/json_to_openstruct.rb', line 6 def self.included(host_class) host_class.extend ClassMethods end |
Instance Method Details
#join(params) ⇒ Object
32 33 34 35 36 |
# File 'lib/json_to_openstruct.rb', line 32 def join(params) hash = self.to_hash parse(hash, params) hash end |
#to_hash ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/json_to_openstruct.rb', line 15 def to_hash hash = {} self.to_h.each do |key, value| if self[key].kind_of?(Array) hash[key] = [] self[key].each do |array_item| hash[key] << array_item.to_hash end elsif self[key].kind_of?(self.class) hash[key] = value.to_hash else hash[key] = value end end hash end |
#to_json ⇒ Object
10 11 12 13 |
# File 'lib/json_to_openstruct.rb', line 10 def to_json hash = self.to_hash hash.to_json end |