Class: Ubcbooker::Config

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



5
6
7
8
9
10
11
12
# File 'lib/ubcbooker/config.rb', line 5

def initialize
  @config_path = File.expand_path("../config.yml", __FILE__)
  if !File.exist?(@config_path)
    create_config_file(@config_path)
  end

  @account = YAML.load_file(@config_path)
end

Instance Attribute Details

#accountObject

Returns the value of attribute account.



3
4
5
# File 'lib/ubcbooker/config.rb', line 3

def 
  @account
end

Instance Method Details

#create_config_file(config_path) ⇒ Object



14
15
16
17
18
# File 'lib/ubcbooker/config.rb', line 14

def create_config_file(config_path)
  File.open(config_path, "w") do |f|
    f.write("---\nusername: sample\npassword: sample")
  end
end

#defined?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/ubcbooker/config.rb', line 35

def defined?
  return @account["username"] != "sample" && @account["password"] != "sample"
end


28
29
30
31
32
33
# File 'lib/ubcbooker/config.rb', line 28

def print_supported_departments
  puts "Supported department options in #{Ubcbooker::VERSION}:"
  BOOKING_URL.keys.each do |d|
    puts "    -  #{d}"
  end
end

#write(username, password) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/ubcbooker/config.rb', line 20

def write(username, password)
  @account["username"] = username
  @account["password"] = password
  new_yml = YAML.dump(@account)
  open(@config_path, "w") { |f| f.write(new_yml) }
  @account = YAML.load_file(@config_path)
end