Class: Csvtree

Inherits:
Object
  • Object
show all
Defined in:
lib/csvtrie.rb

Instance Method Summary collapse

Constructor Details

#initialize(a = Trie.new) ⇒ Csvtree

Returns a new instance of Csvtree.



5
6
7
# File 'lib/csvtrie.rb', line 5

def initialize(a = Trie.new)
  @a = a
end

Instance Method Details

#add_strings(strings) ⇒ Object



21
22
23
# File 'lib/csvtrie.rb', line 21

def add_strings(strings)
  strings.each { |string| @a.add_word(string) }
end

#fill_csv(array_of_words) ⇒ Object



9
10
11
12
13
14
# File 'lib/csvtrie.rb', line 9

def fill_csv(array_of_words)
  CSV.open('../test.csv', 'wb') do |csv|
    csv << %w[id string]
    array_of_words.each_with_index { |word, index| csv << [index, word] }
  end
end

#read_csvObject



16
17
18
19
# File 'lib/csvtrie.rb', line 16

def read_csv
  strings = CSV.parse(File.read('../fill_words.csv'), headers: true).by_col[1]
  add_strings(strings)
end