class Hashematics::Record

A Record object is composed of an inner object (most likely a hash) and provides extra methods for the library.

Attributes

data[R]

Public Class Methods

new(data = {}) click to toggle source
# File lib/hashematics/record.rb, line 20
def initialize(data = {})
  @data = data

  freeze
end

Public Instance Methods

==(other) click to toggle source
# File lib/hashematics/record.rb, line 47
def ==(other)
  eql?(other)
end
[](key) click to toggle source
# File lib/hashematics/record.rb, line 34
def [](key)
  ObjectInterface.get(data, key)
end
eql?(other) click to toggle source

This should allow for Record objects to be compared to:

  • Other Record objects

  • Other data payload objects (most likely Hash objects)

# File lib/hashematics/record.rb, line 41
def eql?(other)
  return eql?(self.class.new(other)) unless other.is_a?(self.class)

  data == other.data
end
id(key) click to toggle source
# File lib/hashematics/record.rb, line 30
def id(key)
  Id.get(id_parts(key))
end
id?(key) click to toggle source
# File lib/hashematics/record.rb, line 26
def id?(key)
  Key.get(key).any? { |p| data[p].to_s.length.positive? }
end

Private Instance Methods

id_parts(key) click to toggle source
# File lib/hashematics/record.rb, line 53
def id_parts(key)
  Key.get(key).each_with_object([]) do |p, arr|
    arr << p
    arr << data[p]
  end
end