Sha256: 4b23ce6e29d3f04d7015b9a556f0438fb8619fa60de39f54f26d8fb58e2464e4
Contents?: true
Size: 657 Bytes
Versions: 1
Compression:
Stored size: 657 Bytes
Contents
class FindMostActiveReader attr_reader :max_taken_books_num, :most_active_reader def initialize(library) @library = library @max_taken_books_num = 0 @most_active_reader = nil end def perform find_the_most_active_reader self end private def find_the_most_active_reader frequency_hash = Hash.new { |hash, key| hash[key] = 0 } library.orders.each do |order| frequency_hash[order.reader] += 1 if frequency_hash[order.reader] > @max_taken_books_num @most_active_reader = order.reader @max_taken_books_num = frequency_hash[order.reader] end end end attr_reader :library end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
bokov_library-1.0.0 | lib/find_most_active_reader.rb |