Class: Fyodor::Library

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/fyodor/library.rb

Instance Method Summary collapse

Constructor Details

#initializeLibrary

Returns a new instance of Library.



11
12
13
14
# File 'lib/fyodor/library.rb', line 11

def initialize
  @books = []
  @rej_empty = 0
end

Instance Method Details

#<<(entry) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/fyodor/library.rb', line 16

def <<(entry)
  if entry.empty?
    @rej_empty += 1
    return
  end

  book(entry.book_title, entry.book_author) << entry
end

#count_desc_unparsedObject



29
30
31
# File 'lib/fyodor/library.rb', line 29

def count_desc_unparsed
  reduce(0) { |acc, book| acc + book.count_desc_unparsed }
end

#count_entriesObject



33
34
35
# File 'lib/fyodor/library.rb', line 33

def count_entries
  reduce(0) { |acc, book| acc + book.size }
end

#count_typesObject



25
26
27
# File 'lib/fyodor/library.rb', line 25

def count_types
  reduce({}) { |acc, book| acc.merge(book.count_types) { |key, val1, val2| val1 + val2 } }
end

#rejectedObject



37
38
39
# File 'lib/fyodor/library.rb', line 37

def rejected
  {empty: @rej_empty, dup: count_rej_dup}
end