Permalink
Browse files

extracted the DataObject as a file parser

  • Loading branch information...
pjurczynski committed Apr 27, 2012
1 parent 2aa7611 commit 4691d0c8c1bbe439cd80cb3f236cd50c1df0759d
File renamed without changes.
@@ -0,0 +1,6 @@
+Feature: I can read a flight table
+
+Scenario: I can read everything from the flight table
+ Given a table in "data/sample/sample-input.txt"
+ When I read it
+ Then I should know what's in it
@@ -0,0 +1,13 @@
+require_relative '../../lib/journey_assistant/flight'
+
+Given /^a table in "([^"]*)"$/ do |flight_table|
+ @f = File.open(flight_table)
+end
+
+When /^I read it$/ do
+ @flights = JourneyAssistant::FlightReader.readCommands(@f)
+end
+
+Then /^I should know what's in it$/ do
+ @flights.should be_a_kind_of Enumerator
+end
Binary file not shown.
@@ -1,2 +1 @@
require 'ruby-debug'
-require './lib/flight.rb'
@@ -1,3 +1,2 @@
require 'csv'
require_relative 'lib/journey_assistant.rb'
-
@@ -0,0 +1,14 @@
+module Data
+ class DataSet
+ def initialize(data)
+ return @data << DataSet.new(data) if data =~ /^\d*$/
+ return @data << DataRow.new(data)
+ end
+ end
+
+ class DataRow
+ def initialize(data)
+ @data = data
+ end
+ end
+end
@@ -1,21 +1,11 @@
# from, to, start, end, cost
# course, time_span
+# return enumerator!
module JourneyAssistant
class Flight
# it is expected to get a data row
def initialize(data)
@from, @to, @departure, @arrival, @cost = data
end
end
-
- class FlightReader
- def self.readCommands(file)
- line = file.readline.strip!
- if line =~ /^\d*$/
- line.to_i.times { readCommands(file) }
- # if just N then invoke the same command N times omitting the next line
- # if long line, then return return it as an array
- if
- end
- end
end

0 comments on commit 4691d0c

Please sign in to comment.