Sha256: cf9ce7db7eab5005176ae5c187bdd74f1690e3cbe28cd5da4e9eda66b47ace9e

Contents?: true

Size: 625 Bytes

Versions: 2

Compression:

Stored size: 625 Bytes

Contents

class HomeController < ApplicationController

  def index
    months = []
    collect_months(months)
    append_current_month(months)

    @months = months.group_by(&:year)
  end

  private

  def collect_months(months)
    oldest = Item.minimum("date")
    newest = Item.maximum("date")

    if oldest and newest
      m = newest.beginning_of_month
      while m >= oldest.beginning_of_month
        months.push m
        m <<= 1
      end
    end
  end

  def append_current_month(months)
    current = Time.now.to_date.beginning_of_month
    unless months.include?(current)
      months.unshift current
    end
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
moneyrail-0.1.6 app/controllers/home_controller.rb
moneyrail-0.1.5 app/controllers/home_controller.rb