Class: Settings

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

Constant Summary collapse

@@zip_codes =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#zip_codesObject

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_hashObject



15
16
17
# File 'lib/settings.rb', line 15

def self.class_hash
    {"zip_codes" => @@zip_codes}
end

.initObject



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_zipsObject



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

def self.reset_zips
    @@zip_code = []
end

.saveObject



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_codesObject



19
20
21
# File 'lib/settings.rb', line 19

def self.zip_codes
    @@zip_codes
end