aboutsummaryrefslogtreecommitdiffstats
path: root/lib/carlosgoce/calendar.rb
blob: e06b61b2890890bc76b422d22fba5e7d9d5211f7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
require 'rubygems'
require 'active_support/core_ext/time'
require 'active_support/core_ext/date'

module CarlosGoce
  class Calendar
    attr_reader :year

    def initialize(year=Date.today.year)
      @year = year
    end

    def to_h
      Hash.new.tap {|h|
        (1..12).each do |month|
          h[month] = Hash.new.tap {|m|
            m[:days] = (1..Time.days_in_month(month, @year)).to_a
            m[:name] = I18n.t('date.month_names')[month].downcase
          }
        end
      }
    end
  end
end