Class: DataHandler
- Inherits:
-
Object
- Object
- DataHandler
- Defined in:
- lib/data_handler.rb
Instance Attribute Summary collapse
-
#follower_letters ⇒ Object
readonly
Returns the value of attribute follower_letters.
-
#start_pairs ⇒ Object
readonly
Returns the value of attribute start_pairs.
Instance Method Summary collapse
-
#initialize ⇒ DataHandler
constructor
A new instance of DataHandler.
- #read_data_file(data_file) ⇒ Object
Constructor Details
#initialize ⇒ DataHandler
Returns a new instance of DataHandler.
3 4 5 6 |
# File 'lib/data_handler.rb', line 3 def initialize @start_pairs = [] @follower_letters = Hash.new('') end |
Instance Attribute Details
#follower_letters ⇒ Object (readonly)
Returns the value of attribute follower_letters.
2 3 4 |
# File 'lib/data_handler.rb', line 2 def follower_letters @follower_letters end |
#start_pairs ⇒ Object (readonly)
Returns the value of attribute start_pairs.
2 3 4 |
# File 'lib/data_handler.rb', line 2 def start_pairs @start_pairs end |
Instance Method Details
#read_data_file(data_file) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/data_handler.rb', line 8 def read_data_file(data_file) File.open(data_file, 'r') do |file| chars = file.read.chomp.downcase.gsub(/\s/, ' ').chars.to_a chars.push(chars[0], chars[1]) populate_followers_and_start_pairs(chars) end end |