Class: Bookery::Factories::ChapterFactory::Chapter

Inherits:
Object
  • Object
show all
Defined in:
lib/bookery/factories/chapter_factory.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(chapter_dir) ⇒ Chapter

Returns a new instance of Chapter.



22
23
24
25
# File 'lib/bookery/factories/chapter_factory.rb', line 22

def initialize(chapter_dir)
  @name = File.basename(chapter_dir)
  @content = combine_chapter_files(chapter_dir)
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



20
21
22
# File 'lib/bookery/factories/chapter_factory.rb', line 20

def content
  @content
end

#nameObject (readonly)

Returns the value of attribute name.



20
21
22
# File 'lib/bookery/factories/chapter_factory.rb', line 20

def name
  @name
end

Instance Method Details

#combine_chapter_files(dir) ⇒ Object



27
28
29
30
31
# File 'lib/bookery/factories/chapter_factory.rb', line 27

def combine_chapter_files(dir)
  Dir.glob(File.join(dir, '*.md')).sort.inject('') do |content, file|
    content << File.read(file) << "\n"
  end
end