Class: Synvert::Core::NodeQuery::Compiler::Attribute
- Inherits:
-
Object
- Object
- Synvert::Core::NodeQuery::Compiler::Attribute
- Defined in:
- lib/synvert/core/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) ⇒ 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/synvert/core/node_query/compiler/attribute.rb', line 10 def initialize(key:, value:, operator: '==') @key = key @value = value @operator = operator end |
Instance Method Details
#match?(node) ⇒ Boolean
Check if the node matches the attribute.
19 20 21 22 |
# File 'lib/synvert/core/node_query/compiler/attribute.rb', line 19 def match?(node) @value.base_node = node if @value.is_a?(DynamicAttribute) node && @value.match?(node.child_node_by_name(@key), @operator) end |
#to_s ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/synvert/core/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}" else "#{@key}=#{@value}" end end |