Class: Fyodor::Book
- Inherits:
-
Object
- Object
- Fyodor::Book
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/fyodor/book.rb
Instance Attribute Summary collapse
-
#author ⇒ Object
readonly
Returns the value of attribute author.
-
#rej_dup ⇒ Object
readonly
Returns the value of attribute rej_dup.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Instance Method Summary collapse
- #<<(entry) ⇒ Object
- #count_desc_unparsed ⇒ Object
- #count_types ⇒ Object
-
#initialize(title, author = nil) ⇒ Book
constructor
A new instance of Book.
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, =nil) raise "Book title can't be empty" if title.to_s.empty? @title = title @author = @entries = Set.new @rej_dup = 0 end |
Instance Attribute Details
#author ⇒ Object (readonly)
Returns the value of attribute author.
9 10 11 |
# File 'lib/fyodor/book.rb', line 9 def @author end |
#rej_dup ⇒ Object (readonly)
Returns the value of attribute rej_dup.
9 10 11 |
# File 'lib/fyodor/book.rb', line 9 def rej_dup @rej_dup end |
#title ⇒ Object (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_unparsed ⇒ Object
33 34 35 |
# File 'lib/fyodor/book.rb', line 33 def count_desc_unparsed count { |entry| ! entry.desc_parsed? } end |
#count_types ⇒ Object
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 |