Class: WhoopeeCushion::Inflate

Inherits:
Object
  • Object
show all
Defined in:
lib/whoopee_cushion.rb

Class Method Summary collapse

Class Method Details

.from_array(value, options = {}) ⇒ Object



24
25
26
# File 'lib/whoopee_cushion.rb', line 24

def self.from_array(value, options = {})
  value.map {|v| from_object v, options}
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, options = {})
  hash = process_hash hash, options
  keys = hash.keys
  model = Struct.new(*keys)
  out = model.new
  hash.each do |key, value|
    out.send("#{key}=", self.from_object(value, options))
  end
  out
end

.from_json(string, options = {}) ⇒ Object



8
9
10
11
# File 'lib/whoopee_cushion.rb', line 8

def self.from_json(string, options = {})
  value = JSON.parse string
  from_object value, options
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, options = {})
  case value
  when Array
    from_array value, options
  when Hash
    from_hash value, options
  else
    value
  end
end