class Beret::Search
Attributes
applicable_block_types[R]
block_set[R]
field_name[R]
Public Class Methods
new(block_set, field_name, options={})
click to toggle source
# File lib/beret/search.rb, line 4 def initialize(block_set, field_name, options={}) @block_set = block_set @field_name = field_name.to_s @applicable_block_types = Array(options.fetch(:in, [])).map(&:to_s) end
Public Instance Methods
results()
click to toggle source
# File lib/beret/search.rb, line 10 def results block_list = flatten_block_set(block_set) block_list.map do |block| if (applicable_block_types.empty? || applicable_block_types.include?(block.type)) && block.attributes.has_key?(field_name) SearchResult.new(block, field_name) end end.compact end
Private Instance Methods
flatten_block_set(block_set)
click to toggle source
# File lib/beret/search.rb, line 23 def flatten_block_set(block_set) block_set.each do |entry| if entry.children block_set = [block_set, flatten_block_set(entry.children)].compact.flatten end end block_set end