Class: Settings
- Inherits:
-
Object
- Object
- Settings
- Defined in:
- lib/settings.rb
Constant Summary collapse
- @@zip_codes =
[]
Instance Attribute Summary collapse
-
#zip_codes ⇒ Object
Returns the value of attribute zip_codes.
Class Method Summary collapse
- .add_zip(zip) ⇒ Object
- .class_hash ⇒ Object
- .init ⇒ Object
- .remove_zip(zip) ⇒ Object
- .reset_zips ⇒ Object
- .save ⇒ Object
- .zip_codes ⇒ Object
Instance Attribute Details
#zip_codes ⇒ Object
Returns the value of attribute zip_codes.
2 3 4 |
# File 'lib/settings.rb', line 2 def zip_codes @zip_codes end |
Class Method Details
.add_zip(zip) ⇒ Object
33 34 35 36 |
# File 'lib/settings.rb', line 33 def self.add_zip(zip) @@zip_codes << zip self.save end |
.class_hash ⇒ Object
15 16 17 |
# File 'lib/settings.rb', line 15 def self.class_hash {"zip_codes" => @@zip_codes} end |
.init ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/settings.rb', line 6 def self.init if !File.file?(SETTINGS_PATH) self.save_zips end file = File.read(SETTINGS_PATH) settings_hash = JSON.parse(file) @@zip_codes = settings_hash["zip_codes"] end |
.remove_zip(zip) ⇒ Object
38 39 40 41 |
# File 'lib/settings.rb', line 38 def self.remove_zip(zip) @@zip_codes.delete(zip) self.save end |
.reset_zips ⇒ Object
23 24 25 |
# File 'lib/settings.rb', line 23 def self.reset_zips @@zip_code = [] end |
.save ⇒ Object
27 28 29 30 31 |
# File 'lib/settings.rb', line 27 def self.save File.open(SETTINGS_PATH, 'w') do |f| f.write(JSON.pretty_generate(self.class_hash)) end end |
.zip_codes ⇒ Object
19 20 21 |
# File 'lib/settings.rb', line 19 def self.zip_codes @@zip_codes end |