Class: Querly::Pattern::Expr::Literal
- Defined in:
- lib/querly/pattern/expr.rb
Instance Attribute Summary collapse
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(type:, value: nil) ⇒ Literal
constructor
A new instance of Literal.
- #test_node(node) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(type:, value: nil) ⇒ Literal
Returns a new instance of Literal.
86 87 88 89 |
# File 'lib/querly/pattern/expr.rb', line 86 def initialize(type:, value: nil) @type = type @value = value end |
Instance Attribute Details
#type ⇒ Object (readonly)
Returns the value of attribute type.
83 84 85 |
# File 'lib/querly/pattern/expr.rb', line 83 def type @type end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
84 85 86 |
# File 'lib/querly/pattern/expr.rb', line 84 def value @value end |
Instance Method Details
#test_node(node) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/querly/pattern/expr.rb', line 91 def test_node(node) case node&.type when :int return false unless type == :int || type == :number if value value == node.children.first else true end when :float return false unless type == :float || type == :number if value value == node.children.first else true end when :true type == :bool && (value == nil || value == true) when :false type == :bool && (value == nil || value == false) when :str return false unless type == :string if value value == node.children.first else true end when :sym return false unless type == :symbol if value value == node.children.first else true end end end |