Sha256: 111edd4fb6632f67dea19dd2b65d482ad982b24e8b0a8d8e4f2ceb49b2cc5249

Contents?: true

Size: 938 Bytes

Versions: 2

Compression:

Stored size: 938 Bytes

Contents

module Lolita
  module Menu
    module Autocomplete
      class Collector

        def initialize(term)
          @links = []
          @term = term
          collect_from_file
        end

        def collect_from_file
          if File.exist?(Lolita::Menu::Autocomplete::FileBuilder.output_file)
            File.open(Lolita::Menu::Autocomplete::FileBuilder.output_file, "r").readlines.each{ |line|
              item = line.to_s.split(" ")
              item.last.to_s.gsub!("\n")
              if item.first.match(/#{@term}/) || item.last.match(/#{@term}/)
                @links << item
              end
            }
          end
        end

        def to_json
          result = []
          @links.each_with_index{|item, index|
            result << {:id => index, :label => "#{item.last} #{item[1] != item[0] ? "(#{item[0]})" : ""}", :value => item.first}
          }
          result
        end

      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
lolita-menu-0.0.13 lib/lolita-menu/autocomplete/collector.rb
lolita-menu-0.0.12 lib/lolita-menu/autocomplete/collector.rb