Class: FilterParam::AST::Literal

Inherits:
Node
  • Object
show all
Defined in:
lib/filter_param/ast/literal.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Node

#accept

Constructor Details

#initialize(value = nil) ⇒ Literal

Returns a new instance of Literal.



6
7
8
# File 'lib/filter_param/ast/literal.rb', line 6

def initialize(value = nil)
  @value = value
end

Instance Attribute Details

#valueObject

Returns the value of attribute value.



4
5
6
# File 'lib/filter_param/ast/literal.rb', line 4

def value
  @value
end

Instance Method Details

#type_cast(type) ⇒ Object

Raises:



10
11
12
13
14
15
16
17
# File 'lib/filter_param/ast/literal.rb', line 10

def type_cast(type)
  return self if type.blank?

  cast_method = "to_#{type}"
  return send(cast_method) if respond_to?(cast_method, true)

  raise InvalidLiteral.new("Cannot cast '#{value}' to #{type}")
end