Class: SearchCopGrammar::Nodes::Collection
- Inherits:
-
Object
- Object
- SearchCopGrammar::Nodes::Collection
show all
- Includes:
- Base
- Defined in:
- lib/search_cop_grammar/nodes.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Base
#and, #can_optimize?, #fulltext?, #not, #optimize!, #or
Constructor Details
#initialize(*nodes) ⇒ Collection
Returns a new instance of Collection.
132
133
134
|
# File 'lib/search_cop_grammar/nodes.rb', line 132
def initialize(*nodes)
@nodes = nodes.flatten
end
|
Instance Attribute Details
#nodes ⇒ Object
Returns the value of attribute nodes.
130
131
132
|
# File 'lib/search_cop_grammar/nodes.rb', line 130
def nodes
@nodes
end
|
Instance Method Details
#can_flatten? ⇒ Boolean
136
137
138
|
# File 'lib/search_cop_grammar/nodes.rb', line 136
def can_flatten?
nodes.any?(&:can_flatten?) || nodes.any? { |node| node.is_a?(self.class) || node.nodes.size == 1 }
end
|
#can_group? ⇒ Boolean
146
147
148
|
# File 'lib/search_cop_grammar/nodes.rb', line 146
def can_group?
nodes.reject(&:fulltext?).any?(&:can_group?) || nodes.select(&:fulltext?).group_by(&:collection).any? { |_, group| group.size > 1 }
end
|
#finalize! ⇒ Object
156
157
158
159
160
|
# File 'lib/search_cop_grammar/nodes.rb', line 156
def finalize!
@nodes = nodes.collect(&:finalize!)
self
end
|
#flatten!(&block) ⇒ Object
140
141
142
143
144
|
# File 'lib/search_cop_grammar/nodes.rb', line 140
def flatten!(&block)
@nodes = nodes.collect(&:flatten!).collect { |node| node.is_a?(self.class) || node.nodes.size == 1 ? node.nodes : node }.flatten
self
end
|
#group! ⇒ Object
150
151
152
153
154
|
# File 'lib/search_cop_grammar/nodes.rb', line 150
def group!
@nodes = nodes.reject(&:fulltext?).collect(&:group!) + nodes.select(&:fulltext?).group_by(&:collection).collect { |collection, group| group.size > 1 ? self.class::Fulltext.new(collection, group) : group.first }
self
end
|