Class: Odin::Types::OdinNumber
Instance Attribute Summary collapse
Attributes inherited from OdinValue
#directives, #modifiers
Instance Method Summary
collapse
Methods inherited from OdinValue
#array?, #binary?, #boolean?, #confidential?, #currency?, #date?, #deprecated?, #duration?, #integer?, #null?, #number?, #numeric?, #object?, #percent?, #reference?, #required?, #string?, #temporal?, #time?, #timestamp?, #verb?
Constructor Details
#initialize(value, raw: nil, **kwargs) ⇒ OdinNumber
Returns a new instance of OdinNumber.
153
154
155
156
157
158
|
# File 'lib/odin/types/values.rb', line 153
def initialize(value, raw: nil, **kwargs)
super(**kwargs)
@value = value.to_f
@raw = raw&.freeze
freeze
end
|
Instance Attribute Details
#raw ⇒ Object
Returns the value of attribute raw.
151
152
153
|
# File 'lib/odin/types/values.rb', line 151
def raw
@raw
end
|
#value ⇒ Object
Returns the value of attribute value.
151
152
153
|
# File 'lib/odin/types/values.rb', line 151
def value
@value
end
|
Instance Method Details
#==(other) ⇒ Object
Also known as:
eql?
162
163
164
|
# File 'lib/odin/types/values.rb', line 162
def ==(other)
other.is_a?(OdinNumber) && value == other.value
end
|
#hash ⇒ Object
167
168
169
|
# File 'lib/odin/types/values.rb', line 167
def hash
[ValueType::NUMBER, value].hash
end
|
#to_s ⇒ Object
171
172
173
|
# File 'lib/odin/types/values.rb', line 171
def to_s
raw || value.to_s
end
|
#type ⇒ Object
160
|
# File 'lib/odin/types/values.rb', line 160
def type; ValueType::NUMBER; end
|
#with_directives(dirs) ⇒ Object
179
180
181
|
# File 'lib/odin/types/values.rb', line 179
def with_directives(dirs)
OdinNumber.new(value, raw: raw, modifiers: modifiers, directives: dirs)
end
|
#with_modifiers(mods) ⇒ Object
175
176
177
|
# File 'lib/odin/types/values.rb', line 175
def with_modifiers(mods)
OdinNumber.new(value, raw: raw, modifiers: mods, directives: directives)
end
|