LibraryStatistics 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/libraryapp.rb +85 -0
- metadata +2 -2
data/lib/libraryapp.rb
CHANGED
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'csv'
|
2
|
+
require_relative 'librarystatistics/category.rb'
|
3
|
+
require_relative 'librarystatistics/library.rb'
|
4
|
+
require_relative 'librarystatistics/csvreader.rb'
|
5
|
+
require_relative 'librarystatistics/categorybuilder.rb'
|
6
|
+
|
7
|
+
class LibraryApp
|
8
|
+
attr_accessor :name, :category_array, :library, :loser_array
|
9
|
+
|
10
|
+
def initialize(args = {})
|
11
|
+
|
12
|
+
@library = Library.new({name: args[:name],
|
13
|
+
quantity: args[:quantity],
|
14
|
+
checkouts: args[:checkouts]})
|
15
|
+
|
16
|
+
inputfile = CategoryBuilder.new
|
17
|
+
@category_array = inputfile.build(@library, args[:file])
|
18
|
+
|
19
|
+
@category_array.each do |count|
|
20
|
+
@library.quantity += count.quantity
|
21
|
+
@library.checkouts += count.checkouts
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
def display
|
30
|
+
output = ""
|
31
|
+
@category_array.each do |stuff|
|
32
|
+
output += "#{stuff.name} \n"
|
33
|
+
output += "Quantity: #{stuff.quantity} \n"
|
34
|
+
output += "% of Total Books: #{stuff.percent_of_total} \n"
|
35
|
+
output += "Checkouts: #{stuff.checkouts} \n"
|
36
|
+
output += "% of Total Checkouts: #{stuff.percent_of_checkouts} \n"
|
37
|
+
output += "Performance (average number of checkouts per book in category): #{stuff.performance} \n"
|
38
|
+
output += "------------- \n"
|
39
|
+
end
|
40
|
+
|
41
|
+
return output
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
def winners
|
47
|
+
best_score = 0.01
|
48
|
+
loser_array = []
|
49
|
+
winner_array = []
|
50
|
+
output = ""
|
51
|
+
|
52
|
+
@category_array.each do |stuff|
|
53
|
+
|
54
|
+
#collect best performers
|
55
|
+
if stuff.performance > best_score
|
56
|
+
best_score = stuff.performance
|
57
|
+
winner_array.clear
|
58
|
+
winner_array << stuff
|
59
|
+
end
|
60
|
+
|
61
|
+
#collect worst performers
|
62
|
+
if stuff.percent_of_checkouts == 0
|
63
|
+
loser_array << stuff
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
output += "Losers:"
|
69
|
+
loser_array.each do |loser|
|
70
|
+
output += "#{loser.name} /n"
|
71
|
+
end
|
72
|
+
|
73
|
+
output += "Winner:"
|
74
|
+
winner_array.each do |winner|
|
75
|
+
output += "#{winner.name}"
|
76
|
+
end
|
77
|
+
|
78
|
+
puts output
|
79
|
+
return output
|
80
|
+
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: LibraryStatistics
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-12-
|
12
|
+
date: 2012-12-10 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: A gem to track the performance of different categories of books in a
|
15
15
|
library
|