Class: WhoopeeCushion::Inflate
- Inherits:
-
Object
- Object
- WhoopeeCushion::Inflate
- Defined in:
- lib/whoopee_cushion.rb
Class Method Summary collapse
- .from_array(value, options = {}) ⇒ Object
- .from_hash(hash, options = {}) ⇒ Object
- .from_json(string, options = {}) ⇒ Object
- .from_object(value, options = {}) ⇒ Object
Class Method Details
.from_array(value, options = {}) ⇒ Object
24 25 26 |
# File 'lib/whoopee_cushion.rb', line 24 def self.from_array(value, = {}) value.map {|v| from_object v, } end |
.from_hash(hash, options = {}) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/whoopee_cushion.rb', line 28 def self.from_hash(hash, = {}) hash = process_hash hash, keys = hash.keys model = Struct.new(*keys) out = model.new hash.each do |key, value| out.send("#{key}=", self.from_object(value, )) end out end |
.from_json(string, options = {}) ⇒ Object
8 9 10 11 |
# File 'lib/whoopee_cushion.rb', line 8 def self.from_json(string, = {}) value = JSON.parse string from_object value, end |
.from_object(value, options = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/whoopee_cushion.rb', line 13 def self.from_object(value, = {}) case value when Array from_array value, when Hash from_hash value, else value end end |