Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: working branch of features from @ianwdunlop #4

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
extra code to deal with Manchester GMPTE extras eg ZD, ZS, ZA
  • Loading branch information
ianwdunlop authored and davidjrice committed Apr 13, 2024
commit 340f5ba18ddd23161c4307821800be03358fc7eb
9 changes: 6 additions & 3 deletions atco.gemspec
Original file line number Diff line number Diff line change
@@ -8,10 +8,10 @@ Gem::Specification.new do |s|
s.version = "0.0.2"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["David Rice"]
s.authors = ["David Rice", "Ian Dunlop"]
s.date = %q{2010-02-22}
s.description = %q{Simple and opinionated library for parsing ATCO-CIF files with Ruby.}
s.email = %q{me@davidjrice.co.uk}
s.email = [%q{me@davidjrice.co.uk}, %q{ianwdunlop@gmail.com}]
s.extra_rdoc_files = [
"README.mdown"
]
@@ -22,7 +22,10 @@ Gem::Specification.new do |s|
"lib/atco.rb",
"lib/atco/journey.rb",
"lib/atco/location.rb",
"lib/atco/stop.rb"
"lib/atco/stop.rb",
"lib/atco/z_location.rb",
"lib/atco/journey_times.rb",
"lib/atco/journey_route.rb"
]
s.homepage = %q{http://github.com/davidjrice/atco}
s.rdoc_options = ["--charset=UTF-8"]
77 changes: 72 additions & 5 deletions lib/atco.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
$:.unshift(File.dirname(__FILE__)) unless
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))

require 'open3'
require 'tempfile'
require 'atco/location'
require 'atco/journey'
require 'atco/stop'

require 'atco/journey_route'
require 'atco/journey_times'
require 'atco/z_location'

module Atco
VERSION = '0.0.1'
@@ -25,6 +24,12 @@ class << self
:journey_header => 'QS'
}

@@gmpte_methods = {
:journey_route => 'ZS',
:stop_location_name => 'ZA',
:journey_times => 'ZD'
}

def parse(file)
@path = File.expand_path(file)
data = File.readlines(@path)
@@ -64,7 +69,39 @@ def parse(file)
end
end
end
return {:header => header, :locations => locations, :journeys => journeys}

@path = File.expand_path(file)
data = File.readlines(@path)
gmpte_info=[]
record_ended = false
data.each do |line|
case line[0,2]
when 'ZD'
puts 'ZD: ' + line
#this is a gmpte specific thing
#it's a new journey so start again
#the assumption is that the journey record is defined before the stops etc
record_ended = false
z_locations=[]
@journey = JourneyTimes.new(parse_journey_times line)
@journey.z_locations=z_locations
@journey.journey_identifiers = []
when 'ZA'
#this is a gmpte specific thing
@journey.z_locations << ZLocation.new(parse_stop_location_name line)
when 'ZS'
#this is a gmpte specific thing
@journey.journey_route = JourneyRoute.new(parse_journey_route line)
when 'QS'
journey_info = parse_journey_header(line)
#each journey can have several records due to bank holidays, weekends etc.
@journey.journey_identifiers << journey_info[:unique_journey_identifier]
#That's the end of the record
gmpte_info << @journey unless record_ended
record_ended = true
end
end
return {:header => header, :locations => locations, :journeys => journeys, :gmpte_info=>gmpte_info}
end

def parse_header(string)
@@ -178,6 +215,36 @@ def parse_journey_header(string)
def parse_value(value)
return value.strip if value
end

#GMPTE has this data
def parse_journey_times(string)
{
:record_identity => string[0,2],
:start_time => string[2,8],
:end_time => string[10,8],
:days_of_the_week_text => parse_value(string[18,48])
}
end

#GMPTE has this data
def parse_journey_route(string)
{
:record_identity => string[0,2],
:provider => string[2,8],
:route_name => parse_value(string[10,4]),
:route_text => parse_value(string[14,50])
}
end

#GMPTE has this data
def parse_stop_location_name(string)
{
:record_identity => string[0,2],
:type => string[2,1],
:identifier => parse_value(string[3,12]),
:name => parse_value(string[14,48])
}
end
end

end