Kaceka2016/ruby_part/dictionary.rb

22 lines
500 B
Ruby
Raw Normal View History

2016-12-08 08:49:58 +01:00
require 'json'
#txt = open("actions.txt")
#print txt.read
txt = open("input.txt")
#puts txt.read
filenames = ["actions.txt", "directions.txt", "movement.txt"]
dictionary = {}
#filenames.each do |name|
#f = File.read(name).include?
#end
txt.each_line do |line|
filenames.each do |name|
if File.read(name).include?line
dictionary[name.chomp('.txt')] = line.chomp("\n")
end
end
end
puts dictionary
File.open("test.json", "w") {|f| f.write(dictionary.to_json)}