Sha256: 1f0ad0df2226b248e75aa0793f2df87e2d44f29d86057529918ab9f07c4236d0

Contents?: true

Size: 1.95 KB

Versions: 19

Compression:

Stored size: 1.95 KB

Contents

module Ratis
  class Pattern
    attr_accessor :route_short_name, :direction, :date, :service_type, :longest, :routeinfos

    def initialize(options)
      self.routeinfos = options[:routeinfos]
    end

    def self.all(conditions)
      short_name   = conditions.delete :route_short_name
      direction    = conditions.delete :direction
      date         = conditions.delete :date
      service_type = conditions.delete :service_type
      longest      = conditions.delete :longest

      raise ArgumentError.new('You must provide a route_short_name') unless short_name
      raise ArgumentError.new('You must provide a direction') unless direction
      raise ArgumentError.new('You must provide a date') unless date
      raise ArgumentError.new('You must provide a service_type') unless service_type
      raise ArgumentError.new('You must provide a longest') unless longest

      Ratis.all_conditions_used? conditions

      response = Request.get 'Getpatterns',
                            {'Route'       => short_name,
                             'Direction'   => direction,
                             'Date'        => date,
                             'Servicetype' => service_type,
                             'Longest'     => longest }

      return nil unless response.success?

      routeinfos = response.to_array(:getpatterns_response, :routes, :routeinfo).map do |rinfo|
                     info = Pattern::RouteInfo.new
                     info.route     = rinfo[:route]
                     info.headsign  = rinfo[:signage]
                     info.operate   = rinfo[:operator]
                     info.effective = rinfo[:effective]
                     info.routeid   = rinfo[:routeid]
                     info.routetype = rinfo[:routetype]
                     info.tripcount = rinfo[:tripcount]
                     info.school    = rinfo[:school]
                     info
                   end

      Pattern.new(:routeinfos => routeinfos)
    end

  end

end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
ratis-3.6.6 lib/ratis/pattern.rb
ratis-3.6.5 lib/ratis/pattern.rb
ratis-3.6.4 lib/ratis/pattern.rb
ratis-3.6.3 lib/ratis/pattern.rb
ratis-3.6.2 lib/ratis/pattern.rb
ratis-3.6.1 lib/ratis/pattern.rb
ratis-3.6.0 lib/ratis/pattern.rb
ratis-3.5.0 lib/ratis/pattern.rb
ratis-3.4.3 lib/ratis/pattern.rb
ratis-3.4.2 lib/ratis/pattern.rb
ratis-3.4.1 lib/ratis/pattern.rb
ratis-3.4.0 lib/ratis/pattern.rb
ratis-3.3.7 lib/ratis/pattern.rb
ratis-3.3.6 lib/ratis/pattern.rb
ratis-3.3.5 lib/ratis/pattern.rb
ratis-3.3.4 lib/ratis/pattern.rb
ratis-3.3.3 lib/ratis/pattern.rb
ratis-3.3.2 lib/ratis/pattern.rb
ratis-3.3.1 lib/ratis/pattern.rb