Class: Graphlyte::Syntax::Value
- Inherits:
-
Data
- Object
- Data
- Graphlyte::Syntax::Value
show all
- Defined in:
- lib/graphlyte/syntax.rb
Overview
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Data
#==, attr_accessor, attr_reader, attributes, #dup, #hash
Constructor Details
#initialize(value = nil, type = nil, **kwargs) ⇒ Value
Returns a new instance of Value.
248
249
250
251
252
253
|
# File 'lib/graphlyte/syntax.rb', line 248
def initialize(value = nil, type = nil, **kwargs)
super(**kwargs)
@value = value if value
@type = type if type
@type ||= value&.type
end
|
Instance Attribute Details
#type ⇒ Object
Returns the value of attribute type.
246
247
248
|
# File 'lib/graphlyte/syntax.rb', line 246
def type
@type
end
|
#value ⇒ Object
Returns the value of attribute value.
246
247
248
|
# File 'lib/graphlyte/syntax.rb', line 246
def value
@value
end
|
Class Method Details
.from_name(name) ⇒ Object
255
256
257
258
259
260
261
262
263
264
265
266
|
# File 'lib/graphlyte/syntax.rb', line 255
def self.from_name(name)
case name
when 'true'
true.to_input_value
when 'false'
false.to_input_value
when 'null'
nil.to_input_value
else
name.to_sym.to_input_value
end
end
|
.from_ruby(object) ⇒ Object
303
304
305
306
307
|
# File 'lib/graphlyte/syntax.rb', line 303
def self.from_ruby(object)
object.to_input_value
rescue NoMethodError
raise IllegalValue, object
end
|
Instance Method Details
#eql?(other) ⇒ Boolean
273
274
275
276
277
278
|
# File 'lib/graphlyte/syntax.rb', line 273
def eql?(other)
return true if super
return true if numeric_eql?(other)
false
end
|
#floating? ⇒ Boolean
291
292
293
294
295
296
297
|
# File 'lib/graphlyte/syntax.rb', line 291
def floating?
return false unless number?
return true if value.is_a?(Float)
return true if value.is_a?(NumericLiteral) && value.floating?
false
end
|
#inspect ⇒ Object
Also known as:
to_s
268
269
270
|
# File 'lib/graphlyte/syntax.rb', line 268
def inspect
"#<#{self.class.name} @type=#{type} @value=#{value.inspect}>"
end
|
#number? ⇒ Boolean
299
300
301
|
# File 'lib/graphlyte/syntax.rb', line 299
def number?
type == :NUMBER
end
|
#numeric_eql?(other) ⇒ Boolean
280
281
282
283
284
285
286
287
288
289
|
# File 'lib/graphlyte/syntax.rb', line 280
def numeric_eql?(other)
return false unless number?
return false unless other&.number?
if floating? || other.floating?
(value.to_f - other.value.to_f) < Float::EPSILON
else
value.to_i == other.value.to_i
end
end
|