Class: ObfuscatedMorseCode::FileParser

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

Constant Summary collapse

FileNotFoundError =
Class.new(StandardError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path) ⇒ FileParser

Returns a new instance of FileParser.



7
8
9
# File 'lib/obfuscated_morse_code/file_parser.rb', line 7

def initialize(file_path)
  @file_path = file_path
end

Instance Attribute Details

#file_pathObject (readonly)

Returns the value of attribute file_path.



3
4
5
# File 'lib/obfuscated_morse_code/file_parser.rb', line 3

def file_path
  @file_path
end

Instance Method Details

#parseObject



11
12
13
14
15
# File 'lib/obfuscated_morse_code/file_parser.rb', line 11

def parse
  File.open(file_path).reduce([], &:<<).map(&:strip)
rescue Errno::ENOENT
  raise FileNotFoundError, "Couldn't locate file: '#{file_path}'"
end