Module: StructureMapper::Hash

Defined in:
lib/structure_mapper.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



104
105
106
# File 'lib/structure_mapper.rb', line 104

def self.included(base)
  base.extend ClassMethods
end

Instance Method Details

#==(other) ⇒ Object



116
117
118
119
120
121
122
# File 'lib/structure_mapper.rb', line 116

def == other
  return false unless self.class == other.class
  self.class.attributes.each do |name,_|
    return false unless self.send(name) == other.send(name)
  end
  true
end

#to_structureObject



108
109
110
111
112
113
114
# File 'lib/structure_mapper.rb', line 108

def to_structure
  ::Hash[
    (self.class.attributes || {}).map do |name,type|
      [name.to_s,public_send(name).to_structure]
    end
  ]
end