Sha256: 68e1445b59050f2e46f51fd5c2d02cea4acbd91b9124206bf51b66e99540f6c8

Contents?: true

Size: 909 Bytes

Versions: 3

Compression:

Stored size: 909 Bytes

Contents

class SearchIndex
  attr_reader :index
  def initialize all_items
    all_citems = all_items.map { |itm| Toc.instance.n2c(itm) }
    skiplist = Regexp.union([/\/search_index\/.*/, /\/bootstrap\/.*/, /\/config\/.*/, /\/tipuesearch\/.*/])
    @index = all_citems.select { |citem| citem.type == "page" && !citem.nitem.binary? && !citem.identifier.match(skiplist)}.map do
      |item|
#        puts "indexing: #{item.title}, match: #{item.identifier.match(skiplist) ? "true" : "false"}"
        nok_parse = Nokogiri::HTML(item.nitem.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:  item.nitem.rep_named(:default).path }
    end
  end

  def clean_string str
    str.nil? ? "" : str.gsub(/(\s+|\"|\“|\”)/, " ")
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
coursegen-0.0.4 lib/coursegen/course/lib/search_data_generator.rb
coursegen-0.0.3 lib/coursegen/course/lib/search_data_generator.rb
coursegen-0.0.2 lib/coursegen/course/lib/search_data_generator.rb