Class: SearchIndex
- Inherits:
-
Object
- Object
- SearchIndex
- Defined in:
- lib/coursegen/course/lib/search_data_generator.rb
Instance Attribute Summary collapse
-
#index ⇒ Object
readonly
Returns the value of attribute index.
Instance Method Summary collapse
- #clean_string(str) ⇒ Object
- #include_in_index?(citem) ⇒ Boolean
-
#initialize(all_items) ⇒ SearchIndex
constructor
A new instance of SearchIndex.
Constructor Details
#initialize(all_items) ⇒ SearchIndex
Returns a new instance of SearchIndex.
3 4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/coursegen/course/lib/search_data_generator.rb', line 3 def initialize all_items all_citems = all_items.map { |itm| Toc.instance.n2c(itm) } @index = all_citems.select { |citem| include_in_index? (citem)}.map do |item| nok_parse = Nokogiri::HTML(all_items[item.identifier].compiled_content).at('body') nok_parse_inner_text = nok_parse.nil? ? "" : nok_parse.inner_text { title: clean_string(item.title), text: clean_string(nok_parse_inner_text), tags: "", loc: all_items[item.identifier].reps[:default].path } end end |
Instance Attribute Details
#index ⇒ Object (readonly)
Returns the value of attribute index.
2 3 4 |
# File 'lib/coursegen/course/lib/search_data_generator.rb', line 2 def index @index end |
Instance Method Details
#clean_string(str) ⇒ Object
16 17 18 |
# File 'lib/coursegen/course/lib/search_data_generator.rb', line 16 def clean_string str str.nil? ? "" : str.gsub(/(\s+|\"|\“|\”)/, " ") end |
#include_in_index?(citem) ⇒ Boolean
20 21 22 23 24 25 |
# File 'lib/coursegen/course/lib/search_data_generator.rb', line 20 def include_in_index?(citem) skiplist = Regexp.union([/\/tipuesearch\/.*/, /\/bootstrap\/.*/, /\/config\/.*/, /\/tipuesearch\/.*/]) citem.type == "page" && !citem.nitem.binary? && !citem.identifier.to_s.match(skiplist) end |