Class: Kamisaku::PDF

Inherits:
Object
  • Object
show all
Defined in:
lib/kamisaku/pdf.rb

Constant Summary collapse

CONTENT_VALIDATOR_MAP =
{
  resume: ResumeContentValidator,
  birthday_invitation: BirthdayInvitationContentValidator
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content_hash:, category:, template:) ⇒ PDF

Returns a new instance of PDF.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/kamisaku/pdf.rb', line 12

def initialize(content_hash:, category:, template:)
  @content_hash = content_hash
  @category = category.to_sym
  @template = template.to_sym

  validator_klass = CONTENT_VALIDATOR_MAP[@category]

  unless validator_klass
    raise Error, "Invalid category '#{@category}'"
  end

  unless validator_klass::TEMPLATES.include?(@template)
    raise Error, "Invalid template '#{@template}'"
  end

  validator_klass.new(content_hash:).validate!
end

Instance Attribute Details

#category ⇒ Object (readonly)

Returns the value of attribute category.



5
6
7
# File 'lib/kamisaku/pdf.rb', line 5

def category
  @category
end

#content_hash ⇒ Object (readonly)

Returns the value of attribute content_hash.



5
6
7
# File 'lib/kamisaku/pdf.rb', line 5

def content_hash
  @content_hash
end

#template ⇒ Object (readonly)

Returns the value of attribute template.



5
6
7
# File 'lib/kamisaku/pdf.rb', line 5

def template
  @template
end

Instance Method Details

#write_to(pdf_location) ⇒ Object



30
31
32
33
34
35
# File 'lib/kamisaku/pdf.rb', line 30

def write_to(pdf_location)
  html_file do |file_path|
    html_file_to_pdf_file(file_path, pdf_location)
    Helpers.(pdf_location)
  end
end

#write_to_html_file(html_location) ⇒ Object



37
38
39
# File 'lib/kamisaku/pdf.rb', line 37

def write_to_html_file(html_location)
  html_file { |file_path| FileUtils.cp(file_path, html_location) }
end