Class: NodeQuery::Compiler::Attribute
- Inherits:
-
Object
- Object
- NodeQuery::Compiler::Attribute
- Defined in:
- lib/node_query/compiler/attribute.rb
Overview
Attribute is a pair of key, value and operator,
Instance Method Summary collapse
-
#initialize(key:, value:, operator: '=') ⇒ Attribute
constructor
Initialize a Attribute.
-
#match?(node, base_node) ⇒ Boolean
Check if the node matches the attribute.
- #to_s ⇒ Object
Constructor Details
#initialize(key:, value:, operator: '=') ⇒ Attribute
Initialize a Attribute.
10 11 12 13 14 |
# File 'lib/node_query/compiler/attribute.rb', line 10 def initialize(key:, value:, operator: '=') @key = key @value = value @operator = operator end |
Instance Method Details
#match?(node, base_node) ⇒ Boolean
Check if the node matches the attribute.
20 21 22 |
# File 'lib/node_query/compiler/attribute.rb', line 20 def match?(node, base_node) node && @value.match?(NodeQuery::Helper.get_target_node(node, @key), base_node, @operator) end |
#to_s ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/node_query/compiler/attribute.rb', line 24 def to_s case @operator when '^=', '$=', '*=', '!=', '=~', '!~', '>=', '>', '<=', '<' "#{@key}#{@operator}#{@value}" when 'in' "#{@key} in (#{@value})" when 'not_in' "#{@key} not in (#{@value})" when 'includes' "#{@key} includes #{@value}" when 'not_includes' "#{@key} not includes #{@value}" else "#{@key}=#{@value}" end end |