class ReadWordTable
Public Instance Methods
call(filename:) { |read_file(filename)| ... }
click to toggle source
# File lib/wordword/operations/read_word_table.rb, line 10 def call(filename:) lines = yield read_file(filename) words = yield parse_lines(lines) Success(words) end
Private Instance Methods
parse_lines(file)
click to toggle source
# File lib/wordword/operations/read_word_table.rb, line 25 def parse_lines(file) words = {} file.each do |line| next if line.strip == "" return Failure(:file_is_not_parseable) unless line.match?(/.*#.*/) word, translated_word = line.split("#").map(&:strip) words[word] = translated_word end Success(words) end
read_file(filename)
click to toggle source
# File lib/wordword/operations/read_word_table.rb, line 19 def read_file(filename) Success(File.readlines(filename)) rescue StandardError Failure(:file_is_not_readable) end