Class: Kindle::Settings

Inherits:
Object
  • Object
show all
Defined in:
lib/kindle/settings.rb

Constant Summary collapse

KINDLE_SETTINGS_DIRECTORY =
"#{ENV["HOME"]}/.kindle"
KINDLE_SETTINGS_FILENAME =
"#{KINDLE_SETTINGS_DIRECTORY}/kindlerc.yml"
KINDLE_DATABASE_FILENAME =
"#{KINDLE_SETTINGS_DIRECTORY}/kindle.db"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSettings

Returns a new instance of Settings.



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/kindle/settings.rb', line 10

def initialize
  create_default_settings_directory unless Dir.exists?(KINDLE_SETTINGS_DIRECTORY)
  if  File.exists?(KINDLE_SETTINGS_FILENAME)
    @settings = YAML.load(File.open(KINDLE_SETTINGS_FILENAME).read) || {}
    settings.each do |name, value|
      set_variable(name.to_s, value)
    end
  else
    @settings = {}
  end
end

Instance Attribute Details

#settingsObject (readonly)

Returns the value of attribute settings.



8
9
10
# File 'lib/kindle/settings.rb', line 8

def settings
  @settings
end

Instance Method Details

#urlObject



22
23
24
25
26
27
28
# File 'lib/kindle/settings.rb', line 22

def url
  if domain.blank?
    raise "Please set :domain: in your settings file!"
  else
    "https://kindle.#{domain}"
  end
end