Class: Kadryll::ShorthandReader

Inherits:
Object
  • Object
show all
Defined in:
lib/kadryll/shorthand_reader.rb

Class Method Summary collapse

Class Method Details

.read(file) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/kadryll/shorthand_reader.rb', line 3

def self.read(file)
  exercises = []
  current_exercise = []
  lines = File.readlines(file)
  lines.each do |line|
    if line.gsub(/\W/, '').empty?
      exercises << current_exercise.join
      current_exercise = []
    else
      current_exercise << line
    end
  end
  exercises << current_exercise.join
  exercises.compact.reject {|e| e.empty?}
end