Skip to content
Browse files

extracted the DataObject as a file parser

  • Loading branch information...
1 parent 2aa7611 commit 4691d0c8c1bbe439cd80cb3f236cd50c1df0759d @pjurczynski committed Apr 27, 2012
View
0 challange_2/.gitignore → .gitignore
File renamed without changes.
View
6 challange_2/features/read_flight_table.feature
@@ -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
View
13 challange_2/features/step_definitions/read_flight_table.rb
@@ -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
View
BIN challange_2/features/support/.env.rb.swp
Binary file not shown.
View
1 challange_2/features/support/env.rb
@@ -1,2 +1 @@
require 'ruby-debug'
-require './lib/flight.rb'
View
1 challange_2/journey_assistant.rb
@@ -1,3 +1,2 @@
require 'csv'
require_relative 'lib/journey_assistant.rb'
-
View
14 challange_2/lib/journey_assistant/data.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
View
12 challange_2/lib/journey_assistant/flight.rb
@@ -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.
Something went wrong with that request. Please try again.