Class: Printavo::Models::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/printavo/models/base.rb

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Base

Returns a new instance of Base.



7
8
9
# File 'lib/printavo/models/base.rb', line 7

def initialize(attributes = {})
  @attributes = (attributes || {}).transform_keys(&:to_s)
end

Instance Method Details

#==(other) ⇒ Object



27
28
29
# File 'lib/printavo/models/base.rb', line 27

def ==(other)
  other.is_a?(self.class) && other.to_h == to_h
end

#[](key) ⇒ Object



11
12
13
# File 'lib/printavo/models/base.rb', line 11

def [](key)
  @attributes[key.to_s]
end

#dig(*keys) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/printavo/models/base.rb', line 15

def dig(*keys)
  keys.map(&:to_s).reduce(@attributes) do |obj, key|
    break nil unless obj.is_a?(Hash)

    obj[key]
  end
end

#inspectObject



31
32
33
# File 'lib/printavo/models/base.rb', line 31

def inspect
  "#<#{self.class.name} #{@attributes.inspect}>"
end

#to_hObject



23
24
25
# File 'lib/printavo/models/base.rb', line 23

def to_h
  @attributes.dup
end