class MobicomCandy::Entity

Constants

PATTERN
UNDERSCORE

Attributes

attributes[R]

Public Class Methods

attribute_name(key) click to toggle source
# File lib/mobicom_candy/entity.rb, line 45
def self.attribute_name(key)
  return key if key.is_a?(Symbol)

  key.split(PATTERN).join(UNDERSCORE).downcase.to_sym
end
attribute_names() click to toggle source
# File lib/mobicom_candy/entity.rb, line 39
def self.attribute_names
  @attribute_names ||= Hash.new do |hash, key|
    hash[key] = attribute_name(key)
  end
end
new(**kwargs) click to toggle source
# File lib/mobicom_candy/entity.rb, line 3
def initialize(**kwargs)
  @attributes = kwargs
end

Public Instance Methods

==(other) click to toggle source
# File lib/mobicom_candy/entity.rb, line 23
def ==(other)
  other.class == self.class && other.attributes == @attributes
end
[]=(key, value) click to toggle source
# File lib/mobicom_candy/entity.rb, line 7
def []=(key, value)
  name = self.class.attribute_names[key]

  @attributes[name] = value
end
method_missing(name, *args) click to toggle source
Calls superclass method
# File lib/mobicom_candy/entity.rb, line 17
def method_missing(name, *args)
  return super unless @attributes.key?(name)

  @attributes[name]
end
respond_to_missing?(name, include_private = false) click to toggle source
Calls superclass method
# File lib/mobicom_candy/entity.rb, line 13
def respond_to_missing?(name, include_private = false)
  @attributes.key?(name) || super
end
to_h() click to toggle source
# File lib/mobicom_candy/entity.rb, line 27
def to_h
  @attributes
end
to_json(*a) click to toggle source
# File lib/mobicom_candy/entity.rb, line 31
def to_json(*a)
  @attributes.to_json(*a)
end