Class: AudioBookCreator::Chapter

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Chapter



5
6
7
8
# File 'lib/audio_book_creator/chapter.rb', line 5

def initialize(options = {})
  options.each { |n, v| public_send("#{n}=", v) }
  @body = Array(body).compact.join("\n\n")
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



3
4
5
# File 'lib/audio_book_creator/chapter.rb', line 3

def body
  @body
end

#numberObject

Returns the value of attribute number.



3
4
5
# File 'lib/audio_book_creator/chapter.rb', line 3

def number
  @number
end

#titleObject

Returns the value of attribute title.



3
4
5
# File 'lib/audio_book_creator/chapter.rb', line 3

def title
  @title
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



26
27
28
29
30
# File 'lib/audio_book_creator/chapter.rb', line 26

def ==(other)
  other.kind_of?(Chapter) &&
    other.number == number &&
    other.title.eql?(title) && other.body.eql?(body)
end

#empty?Boolean



14
15
16
# File 'lib/audio_book_creator/chapter.rb', line 14

def empty?
  body.empty?
end

#filenameObject



10
11
12
# File 'lib/audio_book_creator/chapter.rb', line 10

def filename
  format("chapter%02d", number)
end

#present?Boolean



18
19
20
# File 'lib/audio_book_creator/chapter.rb', line 18

def present?
  !empty?
end

#to_sObject



22
23
24
# File 'lib/audio_book_creator/chapter.rb', line 22

def to_s
  "#{title}\n\n#{body}\n"
end