Class: Category

Inherits:
Object
  • Object
show all
Defined in:
lib/lib_stats/category.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#checkoutsObject (readonly)

Returns the value of attribute checkouts.



2
3
4
# File 'lib/lib_stats/category.rb', line 2

def checkouts
  @checkouts
end

#nameObject (readonly)

Returns the value of attribute name.



2
3
4
# File 'lib/lib_stats/category.rb', line 2

def name
  @name
end

#quantityObject (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_checkoutsObject



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_totalObject



12
13
14
# File 'lib/lib_stats/category.rb', line 12

def percent_of_total
	return (@quantity.fdiv(@library.quantity) * 100).round(1)
end

#performanceObject



22
23
24
# File 'lib/lib_stats/category.rb', line 22

def performance
	return @checkouts.fdiv(@quantity).round(3)
end