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.
131
132
133
|
# File 'lib/search_cop_grammar/nodes.rb', line 131
def initialize(*nodes)
@nodes = nodes.flatten
end
|
Instance Attribute Details
#nodes ⇒ Object
Returns the value of attribute nodes.
129
130
131
|
# File 'lib/search_cop_grammar/nodes.rb', line 129
def nodes
@nodes
end
|
Instance Method Details
#can_flatten? ⇒ Boolean
135
136
137
|
# File 'lib/search_cop_grammar/nodes.rb', line 135
def can_flatten?
nodes.any?(&:can_flatten?) || nodes.any? { |node| node.is_a?(self.class) || node.nodes.size == 1 }
end
|
#can_group? ⇒ Boolean
145
146
147
|
# File 'lib/search_cop_grammar/nodes.rb', line 145
def can_group?
nodes.reject(&:fulltext?).any?(&:can_group?) || nodes.select(&:fulltext?).group_by(&:collection).any? { |_, group| group.size > 1 }
end
|
#finalize! ⇒ Object
155
156
157
158
159
|
# File 'lib/search_cop_grammar/nodes.rb', line 155
def finalize!
@nodes = nodes.collect(&:finalize!)
self
end
|
#flatten!(&block) ⇒ Object
139
140
141
142
143
|
# File 'lib/search_cop_grammar/nodes.rb', line 139
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
149
150
151
152
153
|
# File 'lib/search_cop_grammar/nodes.rb', line 149
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
|