Class: Hashematics::Record
- Inherits:
-
Object
- Object
- Hashematics::Record
- Extended by:
- Forwardable
- Defined in:
- lib/hashematics/record.rb
Overview
A Record object is composed of an inner object (most likely a hash) and provides extra methods for the library.
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #[](key) ⇒ Object
-
#eql?(other) ⇒ Boolean
This should allow for Record objects to be compared to: - Other Record objects - Other data payload objects (most likely Hash objects).
- #id(key) ⇒ Object
- #id?(key) ⇒ Boolean
-
#initialize(data = {}) ⇒ Record
constructor
A new instance of Record.
Constructor Details
#initialize(data = {}) ⇒ Record
Returns a new instance of Record.
20 21 22 23 24 |
# File 'lib/hashematics/record.rb', line 20 def initialize(data = {}) @data = data freeze end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
18 19 20 |
# File 'lib/hashematics/record.rb', line 18 def data @data end |
Instance Method Details
#==(other) ⇒ Object
47 48 49 |
# File 'lib/hashematics/record.rb', line 47 def ==(other) eql?(other) end |
#[](key) ⇒ Object
34 35 36 |
# File 'lib/hashematics/record.rb', line 34 def [](key) ObjectInterface.get(data, key) end |
#eql?(other) ⇒ Boolean
This should allow for Record objects to be compared to:
-
Other Record objects
-
Other data payload objects (most likely Hash objects)
41 42 43 44 45 |
# 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) ⇒ Object
30 31 32 |
# File 'lib/hashematics/record.rb', line 30 def id(key) Id.get(id_parts(key)) end |
#id?(key) ⇒ Boolean
26 27 28 |
# File 'lib/hashematics/record.rb', line 26 def id?(key) Key.get(key).any? { |p| data[p].to_s.length.positive? } end |