Class: Repubmark::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/repubmark/config.rb

Constant Summary collapse

OPTIONAL_KEYS =
%i[
  base_url
  chapter_anchor_prefix
  css_class_annotation
  css_class_blockquote_figure
  css_class_blockquote_blockquote
  css_class_blockquote_figcaption
  css_class_figure_self
  css_class_figure_wrap
  css_class_figures_left
  css_class_figures_right
  css_class_figures_wrap
  css_class_iframe_wrap
  current_path
  images_prefix
  relative_urls
].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(format:, **kwargs) ⇒ Config

Returns a new instance of Config.



33
34
35
36
37
38
# File 'lib/repubmark/config.rb', line 33

def initialize(format:, **kwargs)
  self.format = format
  raise unless (kwargs.keys - OPTIONAL_KEYS).empty?

  @kwargs = kwargs.freeze
end

Instance Attribute Details

#formatObject

Returns the value of attribute format.



23
24
25
# File 'lib/repubmark/config.rb', line 23

def format
  @format
end

Class Method Details

.load_file(filename, profile) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/repubmark/config.rb', line 25

def self.load_file(filename, profile)
  config_data = YAML.safe_load_file filename, aliases: true
  profile_data = config_data[profile]
  raise 'Unknown profile' if profile_data.nil?

  new(**profile_data.transform_keys(&:to_sym))
end

Instance Method Details

#[](key) ⇒ Object



40
41
42
# File 'lib/repubmark/config.rb', line 40

def [](key)
  OPTIONAL_KEYS.include?(key) ? @kwargs[key] : @kwargs.fetch(key)
end