Class: Predicator::Nodes::BaseNode
- Inherits:
-
Object
- Object
- Predicator::Nodes::BaseNode
show all
- Defined in:
- lib/predicator/nodes/base_node.rb
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
#value ⇒ Object
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
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_fixnum ⇒ Object
40
41
42
|
# File 'lib/predicator/nodes/base_node.rb', line 40
def compare_to_fixnum
value.to_i
end
|
#compare_to_float ⇒ Object
44
45
46
|
# File 'lib/predicator/nodes/base_node.rb', line 44
def compare_to_float
value.to_f
end
|
#compare_to_nil ⇒ Object
33
34
35
|
# File 'lib/predicator/nodes/base_node.rb', line 33
def compare_to_nil
raise NilValueError
end
|
#compare_to_string ⇒ Object
48
49
50
|
# File 'lib/predicator/nodes/base_node.rb', line 48
def compare_to_string
value.to_s
end
|
#comparison_method ⇒ Object
29
30
31
|
# File 'lib/predicator/nodes/base_node.rb', line 29
def comparison_method
"compare_to_#{type}"
end
|
#present? ⇒ Boolean
25
26
27
|
# File 'lib/predicator/nodes/base_node.rb', line 25
def present?
!blank?
end
|