Sha256: c2b10b1891e229463463fc251c63cd232e3f0e1d1c308ef5c82530aa8a1ff4a5

Contents?: true

Size: 1.15 KB

Versions: 1

Compression:

Stored size: 1.15 KB

Contents

module MeterCat

  class MetersController < ApplicationController

    layout :set_layout

    before_filter :_authenticate!
    before_filter :_authorize!

    DEFAULT_DAYS = 7

    def index
      if date = params[ :date ]
        @date = Date.civil( date[ :year ].to_i, date[ :month ].to_i, date[ :day ].to_i )
      end
      @days = params[ :days ].to_i if params[ :days ]
      @names = params[ :names ].map { |name| name.to_sym } if params[ :names ]

      @all_names = MeterCat.names
      @date ||= Date.today
      @days ||= DEFAULT_DAYS

      @range = (@date - @days) .. @date
      @meters = Meter.to_h( @range, @names )

      respond_to do |format|
        format.html do
          MeterCat.add( :meter_cat_html )
        end
        format.csv do
          MeterCat.add( :meter_cat_csv )
          render :text => Meter.to_csv( @range, @names ), :content_type => 'text/csv'
        end
      end
    end

    private

    def set_layout
      return MeterCat.config.layout
    end

    def _authenticate!
      instance_eval( &MeterCat.config.authenticate_with )
    end

    def _authorize!
      instance_eval( &MeterCat.config.authorize_with )
    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
meter_cat-0.0.7 app/controllers/meter_cat/meters_controller.rb