Class: LibraryApp

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ LibraryApp

Returns a new instance of LibraryApp.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/libraryapp.rb', line 10

def initialize(args = {})

  @library = Library.new({name: args[:name],
              quantity: args[:quantity],
              checkouts: args[:checkouts]})

  inputfile = CategoryBuilder.new
  @category_array = inputfile.build(@library, args[:file])

  @category_array.each do |count|
    @library.quantity += count.quantity
    @library.checkouts += count.checkouts

  end


end

Instance Attribute Details

#category_arrayObject

Returns the value of attribute category_array.



8
9
10
# File 'lib/libraryapp.rb', line 8

def category_array
  @category_array
end

#libraryObject

Returns the value of attribute library.



8
9
10
# File 'lib/libraryapp.rb', line 8

def library
  @library
end

#loser_arrayObject

Returns the value of attribute loser_array.



8
9
10
# File 'lib/libraryapp.rb', line 8

def loser_array
  @loser_array
end

#nameObject

Returns the value of attribute name.



8
9
10
# File 'lib/libraryapp.rb', line 8

def name
  @name
end

Instance Method Details

#displayObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/libraryapp.rb', line 29

def display
    output = ""
  @category_array.each do |stuff|
    output += "#{stuff.name} \n"
    output += "Quantity: #{stuff.quantity} \n"
    output += "% of Total Books: #{stuff.percent_of_total} \n"
    output += "Checkouts: #{stuff.checkouts} \n"
    output += "% of Total Checkouts: #{stuff.percent_of_checkouts} \n"
    output += "Performance (average number of checkouts per book in category): #{stuff.performance} \n"
    output += "------------- \n"
  end

  return output

end

#winnersObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/libraryapp.rb', line 46

def winners
  best_score = 0.01
  loser_array = []
  winner_array = []
  output = ""

  @category_array.each do |stuff|

  #collect best performers
    if stuff.performance > best_score
      best_score = stuff.performance
      winner_array.clear
      winner_array << stuff
    end

  #collect worst performers
  if stuff.percent_of_checkouts == 0
    loser_array << stuff
  end

  end

  output += "Losers:"
    loser_array.each do |loser|
      output += "#{loser.name} /n"
    end

  output += "Winner:"
    winner_array.each do |winner|
      output += "#{winner.name}"
    end

  puts output
  return output


end