class DiagramController

Public Instance Methods

show() click to toggle source
# File app/controllers/diagram_controller.rb, line 4
def show

  @results = {'weekdays' => [], 'saturdays' => [], 'holidays' => []}

  if params[:id].present? then

      ucode = params[:id].sub("urn:ucode:_","").sub("ucode_","")

      if ( @results_all  = Traindiagram.where( "ucode" =>  ucode ) and @results_all.length == 1 ) then

        @results['weekdays']  = @results_all[0]['weekdays']   unless @results_all[0]['weekdays'].nil?
        @results['saturdays'] = @results_all[0]['saturdays']  unless @results_all[0]['saturdays'].nil?
        @results['holidays']  = @results_all[0]['holidays']   unless @results_all[0]['holidays'].nil?

      elsif ( @results_all  = Busstopdiagram.only(:weekdays).where( "weekDay_ucode" =>  ucode ) and @results_all.length == 1 ) then

        @results['weekdays']  = @results_all[0]['weekdays']
        
      elsif ( @results_all = Busstopdiagram.only(:saturdays).where( "saturDay_ucode" =>  ucode ) and  @results_all.length == 1 ) then

        @results['saturdays']  = @results_all[0]['saturdays']

      elsif ( @results_all = Busstopdiagram.only(:holidays).where( "holiDay_ucode" =>  ucode ) and @results_all.length == 1 ) then

        @results['holidays']  = @results_all[0]['holidays']
 
      elsif ( @results_all = Busstopdiagram.where( "ucode" =>  ucode ) and @results_all.length == 1 ) then

        @results['weekdays']  = @results_all[0]['weekdays']
        @results['saturdays']  = @results_all[0]['saturdays']
        @results['holidays']  = @results_all[0]['holidays']

      elsif (@results_all  = Stationdiagram.only(:weekdays).where( "weekDay_ucode" =>  ucode ) and @results_all.length == 1 ) then

        @results['weekdays']  = @results_all[0]['weekdays']

      elsif ( @results_all = Stationdiagram.only(:saturdays).where( "saturDay_ucode" =>  ucode ) and  @results_all.length == 1 ) then

        @results['holidays']  = @results_all[0]['holidays']

      elsif ( @results_all = Stationdiagram.only(:holidays).where( "holiDay_ucode" =>  ucode ) and @results_all.length == 1 ) then

        @results['holidays']  = @results_all[0]['holidays']

      elsif ( @results_all = Stationdiagram.where( "ucode" =>  ucode ) and @results_all.length == 1 ) then

        @results['weekdays']  = @results_all[0]['weekdays']
        @results['saturdays']  = @results_all[0]['saturdays']
        @results['holidays']  = @results_all[0]['holidays']
 
      else
        head :not_found and return
      end

      respond_to do |format|
          format.json {  render :json => JSON.pretty_generate(@results) } 
      end

  else
       head :bad_request
  end

end