Module: FileReader
- Included in:
- Sentimental
- Defined in:
- lib/file_reader.rb
Instance Method Summary collapse
Instance Method Details
#hash_from_json(filename) ⇒ Object
16 17 18 |
# File 'lib/file_reader.rb', line 16 def hash_from_json(filename) JSON.parse(File.read(filename)) end |
#hash_from_txt(filename) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 |
# 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 |