Class: PuzzleReader::DataSet
- Inherits:
-
Object
- Object
- PuzzleReader::DataSet
- Defined in:
- lib/puzzle_reader.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#initialize(data) ⇒ DataSet
constructor
A new instance of DataSet.
- #method_missing(m, *args, &block) ⇒ Object
- #self ⇒ Object
Constructor Details
#initialize(data) ⇒ DataSet
Returns a new instance of DataSet.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/puzzle_reader.rb', line 15 def initialize(data) @data ||= [] begin current_row = data.next.strip! peek_row = data.peek.strip return if current_row.nil? end while current_row.empty? if current_row =~ /^\d*$/ rows = current_row.to_i.times if peek_row.empty? rows.each { @data << DataSet.new(data) } else rows.each { @data << DataRow.new(data) } end end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/puzzle_reader.rb', line 37 def method_missing(m, *args, &block) begin @data.send(m, *args, &block) rescue NoMethodError super end end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
9 10 11 |
# File 'lib/puzzle_reader.rb', line 9 def data @data end |
Instance Method Details
#each(&block) ⇒ Object
33 34 35 |
# File 'lib/puzzle_reader.rb', line 33 def each(&block) data.each(&block) end |
#self ⇒ Object
11 12 13 |
# File 'lib/puzzle_reader.rb', line 11 def self @data end |