Class: ClockworkComicPDF::Sections

Inherits:
Object
  • Object
show all
Includes:
OptionValidation
Defined in:
lib/clockwork_comic_pdf/section.rb

Overview

this stores the data for each section of the book

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from OptionValidation

#check_options, #check_required

Constructor Details

#initialize(options = {}) ⇒ Sections

Returns a new instance of Sections.



57
58
59
60
61
62
# File 'lib/clockwork_comic_pdf/section.rb', line 57

def initialize(options = {})
  check_options(options.keys, [:front_matter, :body, :end_matter])
  self.front_matter = parse_sections(options[:front_matter])
  self.body = parse_sections(options[:body])
  self.end_matter = parse_sections(options[:end_matter])
end

Instance Attribute Details

#bodyObject



12
13
14
15
# File 'lib/clockwork_comic_pdf/section.rb', line 12

def body
  @body ||= []
  @body
end

#end_matterObject



18
19
20
21
# File 'lib/clockwork_comic_pdf/section.rb', line 18

def end_matter
  @end_matter ||= []
  @end_matter
end

#front_matterObject



7
8
9
# File 'lib/clockwork_comic_pdf/section.rb', line 7

def front_matter
  @front_matter ||= []
end

Instance Method Details

#parse_sections(sections) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/clockwork_comic_pdf/section.rb', line 24

def parse_sections(sections)
  parsed_sections = []
  sections.each do |section|
    parsed_sections << section_by_type(section)
  end
  parsed_sections
end


51
52
53
54
55
# File 'lib/clockwork_comic_pdf/section.rb', line 51

def print_pdf(options = {})
  [front_matter, body, end_matter].each do |chunk|
    chunk.each { |sec| sec.print_pdf(options) }
  end
end

#section_by_type(section) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/clockwork_comic_pdf/section.rb', line 32

def section_by_type(section)
  case section[:type]
  when :comic_pages
    return SectionComicPages.new(section)
  when :text_box
    return SectionTextBox.new(section)
  when :formatted_text_box
    return SectionFormattedTextBox.new(section)
  else
    fail InvalidKeyError, "#{section[:type]} is not a valid section type"
  end
end

#validateObject



45
46
47
48
49
# File 'lib/clockwork_comic_pdf/section.rb', line 45

def validate
  [front_matter, body, end_matter].each do |chunk|
    chunk.each { |sec| sec.validate }
  end
end