Class: Noodall::Articles::Archive::Year
- Inherits:
-
Object
- Object
- Noodall::Articles::Archive::Year
- Defined in:
- lib/noodall/articles/archive.rb
Instance Attribute Summary collapse
-
#months ⇒ Object
readonly
Returns the value of attribute months.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
-
#year ⇒ Object
readonly
Returns the value of attribute year.
Instance Method Summary collapse
-
#initialize(year, value) ⇒ Year
constructor
A new instance of Year.
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
#months ⇒ Object (readonly)
Returns the value of attribute months.
41 42 43 |
# File 'lib/noodall/articles/archive.rb', line 41 def months @months end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
41 42 43 |
# File 'lib/noodall/articles/archive.rb', line 41 def total @total end |
#year ⇒ Object (readonly)
Returns the value of attribute year.
41 42 43 |
# File 'lib/noodall/articles/archive.rb', line 41 def year @year end |