Class: Dolibarr::Record
- Inherits:
-
Object
- Object
- Dolibarr::Record
- Defined in:
- lib/dolibarr/record.rb
Overview
Base for the gem's value objects (Invoice, Payment, Thirdparty). A thin, read-only view over a normalised response hash: amounts are already coerced to BigDecimal by Coerce at construction, string keys are preserved, and the full payload stays reachable through #raw / #[] so nothing the API returned is ever hidden.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#raw ⇒ Hash
readonly
The normalised (amount-coerced) payload.
Class Method Summary collapse
-
.from(hash) ⇒ Object
Build from a raw parsed response hash, coercing amounts.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
Two records are equal when they are the same class and wrap the same payload.
-
#[](key) ⇒ Object
Read any field by its Dolibarr key.
-
#hash ⇒ Integer
A hash consistent with #==, so records key Hashes / Sets correctly.
-
#id ⇒ String?
The object id (Dolibarr returns it as a string).
-
#initialize(raw) ⇒ Record
constructor
A new instance of Record.
-
#to_h ⇒ Hash
The normalised payload.
Constructor Details
#initialize(raw) ⇒ Record
Returns a new instance of Record.
18 19 20 |
# File 'lib/dolibarr/record.rb', line 18 def initialize(raw) @raw = raw || {} end |
Instance Attribute Details
#raw ⇒ Hash (readonly)
Returns the normalised (amount-coerced) payload.
10 11 12 |
# File 'lib/dolibarr/record.rb', line 10 def raw @raw end |
Class Method Details
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
Two records are equal when they are the same class and wrap the same payload.
36 37 38 |
# File 'lib/dolibarr/record.rb', line 36 def ==(other) other.is_a?(self.class) && raw == other.raw end |
#[](key) ⇒ Object
Read any field by its Dolibarr key.
24 25 26 |
# File 'lib/dolibarr/record.rb', line 24 def [](key) raw[key.to_s] end |
#hash ⇒ Integer
Returns a hash consistent with #==, so records key Hashes / Sets correctly.
42 43 44 |
# File 'lib/dolibarr/record.rb', line 42 def hash raw.hash end |
#id ⇒ String?
Returns the object id (Dolibarr returns it as a string).
29 30 31 |
# File 'lib/dolibarr/record.rb', line 29 def id self['id'] end |
#to_h ⇒ Hash
Returns the normalised payload.
47 48 49 |
# File 'lib/dolibarr/record.rb', line 47 def to_h raw end |