Class: GOBL::Value
Overview
Base class for single value structs in the GOBL Schema
Direct Known Subclasses
CBC::Code, CBC::Key, Cal::Date, DSig::Signature, Enum, L10n::Code, UUID::UUID
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Returns whether the current value is equal to a given one.
- #as_json ⇒ Object private
-
#eql?(other) ⇒ Boolean
Returns whether the current value is equal to a given one, unlike ‘#==`, without doing any coercion.
-
#hash ⇒ Integer
Returns a integer hash code of the current value that respects the following property: Given objects ‘a` and `b`.
-
#initialize(value) ⇒ Value
constructor
Initializes a new value object that corresponds to a given value.
-
#to_s ⇒ String
Returns the string representation of the current object.
-
#to_sym ⇒ Symbol
Returns the symbol representation of the current object.
Methods inherited from Struct
from_data, from_json!, #to_json
Constructor Details
#initialize(value) ⇒ Value
Initializes a new value object that corresponds to a given value. The value can be a ‘Symbol`, a `String` or anything coercible into one (via `#to_s`).
12 13 14 15 |
# File 'lib/gobl/value.rb', line 12 def initialize(value) super() self._value = value.to_s end |
Instance Method Details
#==(other) ⇒ Boolean
Returns whether the current value is equal to a given one. In addition to objects of the same type, the current object can be compared to a ‘Symbol`, a `String` or anything coercible into one (via `#to_s`)
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/gobl/value.rb', line 38 def ==(other) case other when self.class _value == other._value when Symbol to_sym == other else to_s == other.to_s end end |
#as_json ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
69 70 71 |
# File 'lib/gobl/value.rb', line 69 def as_json(...) _value.as_json(...) end |
#eql?(other) ⇒ Boolean
Returns whether the current value is equal to a given one, unlike ‘#==`, without doing any coercion. That is, the other object must be of the same class to return true.
56 57 58 |
# File 'lib/gobl/value.rb', line 56 def eql?(other) self.class == other.class && _value.eql?(other._value) end |
#hash ⇒ Integer
Returns a integer hash code of the current value that respects the following property: Given objects ‘a` and `b`. If `a.eql?(b)`, then `a.hash == b.hash`.
64 65 66 |
# File 'lib/gobl/value.rb', line 64 def hash [self.class.name, _value].hash end |
#to_s ⇒ String
Returns the string representation of the current object
20 21 22 |
# File 'lib/gobl/value.rb', line 20 def to_s _value.to_s end |
#to_sym ⇒ Symbol
Returns the symbol representation of the current object
27 28 29 |
# File 'lib/gobl/value.rb', line 27 def to_sym to_s.parameterize.underscore.to_sym end |