module FileReader
Public Instance Methods
hash_from_json(filename)
click to toggle source
# File lib/file_reader.rb, line 16 def hash_from_json(filename) JSON.parse(File.read(filename)) end
hash_from_txt(filename)
click to toggle source
# File lib/file_reader.rb, line 4 def hash_from_txt(filename) new_words = {} File.open(filename) do |file| file.each_line do |line| parsed_line = line.chomp.scan(/^([^\s]+)\s+(.+)/).first next unless parsed_line new_words[parsed_line[1]] = parsed_line[0].to_f end end new_words end