Module: Thelister::ClassMethods
- Defined in:
- lib/listof/thelister.rb
Constant Summary collapse
- DATA_PATH =
File.dirname(File.dirname(File.dirname(__FILE__))) + '/data/'
- DOT_EXTENSION =
".txt"
Instance Method Summary collapse
Instance Method Details
#all ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/listof/thelister.rb', line 32 def all() contents_hash = {} Dir.glob("#{DATA_PATH}/*#{DOT_EXTENSION}").each_with_index do |path, index| contents_hash[index] = File.basename(path, DOT_EXTENSION) end contents_hash end |
#file_for_query ⇒ Object
28 29 30 |
# File 'lib/listof/thelister.rb', line 28 def file_for_query "#{DATA_PATH}/#{@query}#{DOT_EXTENSION}" end |
#find(query) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/listof/thelister.rb', line 8 def find(query) @query = query contents_hash = {} if File.file?(file_for_query) f = File.open(file_for_query) _lineno = 1 f.each_line.with_index do |line| line = line.strip if !line.start_with?("#") and line.length >= 1 contents_hash[_lineno] = line _lineno += 1 elsif line.start_with?("#") l = line.sub("#", "").split() contents_hash[l[0]] = l[1] end end end contents_hash end |