Class: Cheepub::Generator
- Inherits:
-
Object
- Object
- Cheepub::Generator
- Defined in:
- lib/cheepub/generator.rb,
lib/cheepub/generator/epub.rb,
lib/cheepub/generator/latex.rb
Defined Under Namespace
Constant Summary collapse
- ROLES =
%i{aut edt trl ill cov cre pht cwt nrt}
Instance Method Summary collapse
- #add_creator(name, role) ⇒ Object
- #apply_params(params) ⇒ Object
- #check_params(params) ⇒ Object
- #execute ⇒ Object
-
#initialize(src, params) ⇒ Generator
constructor
A new instance of Generator.
- #output_file ⇒ Object
- #parse_creator(creator) ⇒ Object
Constructor Details
#initialize(src, params) ⇒ Generator
Returns a new instance of Generator.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/cheepub/generator.rb', line 6 def initialize(src, params) if src.kind_of? Cheepub::Content @src = nil @content = src else @src = src @content = Cheepub::Content.new(File.read(@src)) end @params = params end |
Instance Method Details
#add_creator(name, role) ⇒ Object
44 45 46 |
# File 'lib/cheepub/generator.rb', line 44 def add_creator(name, role) raise NotImplementedError end |
#apply_params(params) ⇒ Object
54 55 56 |
# File 'lib/cheepub/generator.rb', line 54 def apply_params(params) raise NotImplementedError end |
#check_params(params) ⇒ Object
48 49 50 51 52 |
# File 'lib/cheepub/generator.rb', line 48 def check_params(params) if !params[:author] || !params[:title] raise Cheepub::Error, "you must use `--author` and `--title`, or add front-matter in Markdown file." end end |
#execute ⇒ Object
17 18 19 20 21 22 |
# File 'lib/cheepub/generator.rb', line 17 def execute params = @content.header.merge(@params){|key, val, arg_val| arg_val.nil? ? val : arg_val} check_params(params) apply_params(params) output_file(params) end |
#output_file ⇒ Object
24 25 26 |
# File 'lib/cheepub/generator.rb', line 24 def output_file raise NotImplementedError end |
#parse_creator(creator) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/cheepub/generator.rb', line 28 def parse_creator(creator) case creator when nil return when String add_creator(name, "aut") else creator.each do |role, name| if !ROLES.include?(role) raise Cheepub::Error, "invalid role: '#{role}' for creator '#{name}'." end add_creator(name, role) end end end |