Class: Githug::Profile

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

Constant Summary collapse

PROFILE_FILE =
".profile.yml"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(settings) ⇒ Profile

Returns a new instance of Profile.



42
43
44
# File 'lib/githug/profile.rb', line 42

def initialize(settings)
  @settings = settings
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/githug/profile.rb', line 33

def method_missing(method, *args, &block)
  if method.to_s.end_with?("=")
    method = method.to_s.chop.to_sym
    return settings[method] = args[0] if settings.include?(method)
  end
  return(settings[method]) if settings.include?(method)
  super
end

Instance Attribute Details

#settingsObject

Returns the value of attribute settings.



6
7
8
# File 'lib/githug/profile.rb', line 6

def settings
  @settings
end

Class Method Details

.loadObject



9
10
11
# File 'lib/githug/profile.rb', line 9

def load
  self.new(settings)
end

Instance Method Details

#level_bumpObject



58
59
60
61
62
# File 'lib/githug/profile.rb', line 58

def level_bump
  settings[:completed_levels] << level
  settings[:current_levels] = levels
  set_level(next_level)
end

#saveObject



46
47
48
49
50
# File 'lib/githug/profile.rb', line 46

def save
  File.open(PROFILE_FILE, 'w') do |out|
    YAML.dump(settings, out)
  end
end

#set_level(name) ⇒ Object



52
53
54
55
56
# File 'lib/githug/profile.rb', line 52

def set_level(name)
  settings[:level] = name
  reset!
  save
end