Class: Fyodor::Book

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title, author = nil) ⇒ Book

Returns a new instance of Book.



13
14
15
16
17
18
19
20
# File 'lib/fyodor/book.rb', line 13

def initialize(title, author=nil)
  raise "Book title can't be empty" if title.to_s.empty?

  @title = title
  @author = author
  @entries = Set.new
  @rej_dup = 0
end

Instance Attribute Details

#authorObject (readonly)

Returns the value of attribute author.



9
10
11
# File 'lib/fyodor/book.rb', line 9

def author
  @author
end

#rej_dupObject (readonly)

Returns the value of attribute rej_dup.



9
10
11
# File 'lib/fyodor/book.rb', line 9

def rej_dup
  @rej_dup
end

#titleObject (readonly)

Returns the value of attribute title.



9
10
11
# File 'lib/fyodor/book.rb', line 9

def title
  @title
end

Instance Method Details

#<<(entry) ⇒ Object



22
23
24
25
26
# File 'lib/fyodor/book.rb', line 22

def <<(entry)
  return if entry.empty?
  # #add? returns nil if the entry was duplicated
  @rej_dup += 1 if @entries.add?(entry).nil?
end

#count_desc_unparsedObject



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

def count_desc_unparsed
  count { |entry| ! entry.desc_parsed? }
end

#count_typesObject



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

def count_types
  list = group_by(&:type).map { |k, v| [k, v.size] }
  Hash[list]
end