Class: Category
- Inherits:
-
Object
- Object
- Category
- Defined in:
- lib/lib_stats/category.rb
Instance Attribute Summary collapse
-
#checkouts ⇒ Object
readonly
Returns the value of attribute checkouts.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#quantity ⇒ Object
readonly
Returns the value of attribute quantity.
Instance Method Summary collapse
-
#initialize(library, args = {}) ⇒ Category
constructor
A new instance of Category.
- #percent_of_checkouts ⇒ Object
- #percent_of_total ⇒ Object
- #performance ⇒ Object
Constructor Details
#initialize(library, args = {}) ⇒ Category
Returns a new instance of Category.
5 6 7 8 9 10 |
# File 'lib/lib_stats/category.rb', line 5 def initialize(library, args = {}) @library = library @name = args[:name] || "Category Name" @quantity = args[:quantity].to_i || 0 @checkouts = args[:checkouts].to_i || 0 end |
Instance Attribute Details
#checkouts ⇒ Object (readonly)
Returns the value of attribute checkouts.
2 3 4 |
# File 'lib/lib_stats/category.rb', line 2 def checkouts @checkouts end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
2 3 4 |
# File 'lib/lib_stats/category.rb', line 2 def name @name end |
#quantity ⇒ Object (readonly)
Returns the value of attribute quantity.
2 3 4 |
# File 'lib/lib_stats/category.rb', line 2 def quantity @quantity end |
Instance Method Details
#percent_of_checkouts ⇒ Object
17 18 19 |
# File 'lib/lib_stats/category.rb', line 17 def percent_of_checkouts return (@checkouts.fdiv(@library.checkouts) * 100).round(1) end |
#percent_of_total ⇒ Object
12 13 14 |
# File 'lib/lib_stats/category.rb', line 12 def percent_of_total return (@quantity.fdiv(@library.quantity) * 100).round(1) end |
#performance ⇒ Object
22 23 24 |
# File 'lib/lib_stats/category.rb', line 22 def performance return @checkouts.fdiv(@quantity).round(3) end |