Class: Predicator::Nodes::BaseNode

Inherits:
Object
  • Object
show all
Defined in:
lib/predicator/nodes/base_node.rb

Direct Known Subclasses

DateNode, FixnumNode, FloatNode, NilClassNode, StringNode

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ BaseNode

Returns a new instance of BaseNode.



15
16
17
# File 'lib/predicator/nodes/base_node.rb', line 15

def initialize value
  @value = value
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



4
5
6
# File 'lib/predicator/nodes/base_node.rb', line 4

def value
  @value
end

Class Method Details

.class_for(value) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/predicator/nodes/base_node.rb', line 6

def self.class_for value
  class_name = "#{value.class.name}Node"
  if ::Predicator::Nodes.const_defined? class_name
    ::Predicator::Nodes.const_get class_name
  else
    raise UnknownNodeTypeError, "Unknown node type for #{value.class} (#{value.inspect})"
  end
end

Instance Method Details

#blank?Boolean

Returns:

  • (Boolean)


19
20
21
22
23
# File 'lib/predicator/nodes/base_node.rb', line 19

def blank?
  value.respond_to?(:empty?) ?
    !!value.empty? :
    !value
end

#compare_to_fixnumObject

def compare_to_date end



40
41
42
# File 'lib/predicator/nodes/base_node.rb', line 40

def compare_to_fixnum
  value.to_i
end

#compare_to_floatObject



44
45
46
# File 'lib/predicator/nodes/base_node.rb', line 44

def compare_to_float
  value.to_f
end

#compare_to_nilObject

Raises:



33
34
35
# File 'lib/predicator/nodes/base_node.rb', line 33

def compare_to_nil
  raise NilValueError
end

#compare_to_stringObject



48
49
50
# File 'lib/predicator/nodes/base_node.rb', line 48

def compare_to_string
  value.to_s
end

#comparison_methodObject



29
30
31
# File 'lib/predicator/nodes/base_node.rb', line 29

def comparison_method
  "compare_to_#{type}"
end

#present?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/predicator/nodes/base_node.rb', line 25

def present?
  !blank?
end