Class: Preferences

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/preferences.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePreferences

Returns a new instance of Preferences.



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

def initialize
  preferences_path = File.join(Dir.home, ".dominosjp.yml")
  return unless File.exist?(preferences_path)

  prefs = YAML.safe_load(File.read(preferences_path)).map { |k, v| [(k.to_sym rescue k), v] }.to_h

  self.email = prefs[:email] if prefs[:email]
  self.name = prefs[:name] if prefs[:name]
  self.phone_number = prefs[:phone_number] if prefs[:phone_number]
  self.credit_card = CreditCard.new(prefs[:credit_card]) if prefs[:credit_card]
  self.note = prefs[:note] if prefs[:note]
end

Instance Attribute Details

#credit_cardObject

Returns the value of attribute credit_card.



7
8
9
# File 'lib/preferences.rb', line 7

def credit_card
  @credit_card
end

#emailObject

Returns the value of attribute email.



7
8
9
# File 'lib/preferences.rb', line 7

def email
  @email
end

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/preferences.rb', line 7

def name
  @name
end

#noteObject

Returns the value of attribute note.



7
8
9
# File 'lib/preferences.rb', line 7

def note
  @note
end

#phone_numberObject

Returns the value of attribute phone_number.



7
8
9
# File 'lib/preferences.rb', line 7

def phone_number
  @phone_number
end