Class: Noodall::Articles::Archive::Year

Inherits:
Object
  • Object
show all
Defined in:
lib/noodall/articles/archive.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(year, value) ⇒ Year

Returns a new instance of Year.



43
44
45
46
47
48
49
50
51
52
# File 'lib/noodall/articles/archive.rb', line 43

def initialize(year, value)
  @year = year.to_i
  if value.is_a?( Enumerable )
    @months = value.map{ |m| m.to_i  }
  else
    @months = [0,0,0,0,0,0,0,0,0,0,0,0]
    @months[value.to_i] = 1
  end
  @total = @months.inject {|sum, n| (sum + n).to_i }
end

Instance Attribute Details

#monthsObject (readonly)

Returns the value of attribute months.



41
42
43
# File 'lib/noodall/articles/archive.rb', line 41

def months
  @months
end

#totalObject (readonly)

Returns the value of attribute total.



41
42
43
# File 'lib/noodall/articles/archive.rb', line 41

def total
  @total
end

#yearObject (readonly)

Returns the value of attribute year.



41
42
43
# File 'lib/noodall/articles/archive.rb', line 41

def year
  @year
end