Class: AudioBookCreator::Defaulter

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/audio_book_creator/defaulter.rb

Constant Summary collapse

ATTRIBUTES =
[:title_path, :body_path, :link_path, :chapter_path]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(page_def, book_def) ⇒ Defaulter

Returns a new instance of Defaulter.



13
14
15
16
# File 'lib/audio_book_creator/defaulter.rb', line 13

def initialize(page_def, book_def)
  @page_def    = page_def
  @book_def    = book_def
end

Instance Attribute Details

#book_defObject

Returns the value of attribute book_def.



10
11
12
# File 'lib/audio_book_creator/defaulter.rb', line 10

def book_def
  @book_def
end

#page_defObject

Returns the value of attribute page_def.



9
10
11
# File 'lib/audio_book_creator/defaulter.rb', line 9

def page_def
  @page_def
end

#settingsObject



23
24
25
26
# File 'lib/audio_book_creator/defaulter.rb', line 23

def settings
  # in the future, move into pages
  @settings ||= PageDb.new("settings.db", "settings", true)
end

Instance Method Details

#hostObject



18
19
20
21
# File 'lib/audio_book_creator/defaulter.rb', line 18

def host
  url = book_def.urls.first
  url && URI.parse(url).host
end

#load_unset_valuesObject



28
29
30
31
# File 'lib/audio_book_creator/defaulter.rb', line 28

def load_unset_values
  value = host && settings[host]
  value.each { |n, v| public_send("#{n}=", v) } if value
end

#storeObject



33
34
35
36
37
38
39
# File 'lib/audio_book_creator/defaulter.rb', line 33

def store
  return unless host
  settings[host] = ATTRIBUTES.each_with_object(settings[host] || {}) do |attr, h|
    v = public_send(attr)
    h[attr] = v if v
  end
end