Class: JekyllBuildEbook::Config
- Inherits:
-
Object
- Object
- JekyllBuildEbook::Config
- Defined in:
- lib/jekyll-build-ebook/config.rb
Constant Summary collapse
- DEFAULTS =
{ 'ebook' => { 'destination' => File.join(Dir.pwd, '_ebook'), 'layout' => 'ebook', }, }.freeze
- REQUIRED_FIELDS =
%w[identifier title language].freeze
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #destination_path(ext: 'epub') ⇒ Object
-
#initialize(site_config) ⇒ Config
constructor
A new instance of Config.
Constructor Details
#initialize(site_config) ⇒ Config
Returns a new instance of Config.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/jekyll-build-ebook/config.rb', line 16 def initialize(site_config) @data = { 'file_name' => site_config['title'], 'identifier' => site_config['url'].nil? ? SecureRandom.uuid : "#{site_config['url']}#{site_config['base_url']}", 'title' => site_config['title'], 'language' => site_config['language'] || site_config['lang'], 'creator' => case site_config['author'] when String site_config['author'] when Hash site_config['author']['name'] else nil end, }.merge(site_config['ebook']) REQUIRED_FIELDS.each do |field| raise InvalidConfigError, "#{field} is required" if data[field].nil? end end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
14 15 16 |
# File 'lib/jekyll-build-ebook/config.rb', line 14 def data @data end |
Instance Method Details
#[](key) ⇒ Object
37 38 39 |
# File 'lib/jekyll-build-ebook/config.rb', line 37 def [](key) data[key] end |
#destination_path(ext: 'epub') ⇒ Object
41 42 43 |
# File 'lib/jekyll-build-ebook/config.rb', line 41 def destination_path(ext: 'epub') "#{File.join(data['destination'], data['file_name'])}.#{ext}" end |