module GTFS::Model::ClassMethods

Public Instance Methods

each(filename) { |parse_model(headers, fields)| ... } click to toggle source
# File lib/gtfs/gtfs_gem_patch.rb, line 6
def each(filename)
  headers = nil
  CSV.foreach(filename, :headers => true) do |row|
    headers ||= unprefixed_headers(row.headers)
    yield parse_model(headers, row.fields)
  end
end
parse_model(headers, fields, options={}) click to toggle source
# File lib/gtfs/gtfs_gem_patch.rb, line 14
def parse_model(headers, fields, options={})
  self.new(Hash[headers.zip(fields)])
end
parse_models(data, options={}) click to toggle source
# File lib/gtfs/gtfs_gem_patch.rb, line 18
def parse_models(data, options={})
  return [] if data.nil? || data.empty?

  models = []
  headers = nil
  CSV.parse(data, :headers => true) do |row|
    headers ||= unprefixed_headers(row.headers)
    model = parse_model(headers, row.fields)
    models << model if options[:strict] == false || model.valid?
  end
  models
end
unprefixed_headers(headers) click to toggle source
# File lib/gtfs/gtfs_gem_patch.rb, line 31
def unprefixed_headers(headers)
  headers.collect{|h| h.gsub(/^#{prefix}/, '')}
end