Module: Holotype::InstanceMethods

Defined in:
lib/holotype.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



90
91
92
# File 'lib/holotype.rb', line 90

def attributes
  @attributes
end

Instance Method Details

#==(other) ⇒ Object



114
115
116
117
118
119
120
# File 'lib/holotype.rb', line 114

def == other
  return false unless self.class == other.class

  attributes.all? do |name, attribute|
    attribute.value == other.attributes[name].value
  end
end

#frozen?Boolean

Returns:

  • (Boolean)


97
98
99
# File 'lib/holotype.rb', line 97

def frozen?
  true
end

#initialize(attributes) ⇒ Object



92
93
94
95
# File 'lib/holotype.rb', line 92

def initialize(attributes)
  __holotype_check_for_missing_required attributes
  __holotype_store attributes
end

#inspectObject



126
127
128
129
130
131
132
# File 'lib/holotype.rb', line 126

def inspect
  data = to_hash
           .map { |attribute, value| "#{attribute}: #{value.inspect}" }
           .join(', ')

  "#{self.class.name}(#{data})"
end

#to_hashObject



101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/holotype.rb', line 101

def to_hash
  Hash[
    attributes
      .map do |key, attribute|
        definition = attribute.definition

        value = __holotype_hashify attribute.value

        [key, value]
      end
  ]
end

#with(**attributes) ⇒ Object



122
123
124
# File 'lib/holotype.rb', line 122

def with **attributes
  self.class.new(**to_hash.merge(**attributes))
end