Class: Structural::Hashifier

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

Class Method Summary collapse

Class Method Details

.as_data(v) ⇒ Object



11
12
13
14
15
16
# File 'lib/structural/hashifier.rb', line 11

def self.as_data(v)
  case v
  when Structural::Model then v.data
  when Array then v.first.is_a?(Structural::Model) ? v.map(&:data) : v
  else v end
end

.hashify(data) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/structural/hashifier.rb', line 3

def self.hashify(data)
  {}.tap do |hash|
    data.each do |key, value|
      hash[key.to_sym] = as_data(value)
    end
  end
end