Class: Users::AttributeClass

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

Overview

Base attribute class which attribute types derive from. Class methods are invoked by subclasses to define their context

Class Method Summary collapse

Class Method Details

.callbacks(callbacks = nil) ⇒ Object

hash of callbacks to invoke on various events including

  • :progression

  • :regression

  • :level_up

  • :level_down


165
166
167
168
169
170
171
# File 'lib/users/attribute.rb', line 165

def self.callbacks(callbacks = nil)
  unless callbacks.nil?
    @callbacks = callbacks
    @callbacks.each { |k,v| @callbacks[k] = v.is_a?(Array) ? v : [v] }
  end
  @callbacks
end

.create_attribute(attr_args = {}) ⇒ Object

Return new attribute initialized for the specified class


127
128
129
130
# File 'lib/users/attribute.rb', line 127

def self.create_attribute(attr_args = {})
  ac = self
  Attribute.new(attr_args.merge({:type => ac}))
end

.description(description = nil) ⇒ Object

description of the attribute class


139
140
141
142
# File 'lib/users/attribute.rb', line 139

def self.description(description = nil)
  @description = description.gsub(/\s+/, " ") unless description.nil?
  @description
end

.id(id = nil) ⇒ Object

id of the attribute class


133
134
135
136
# File 'lib/users/attribute.rb', line 133

def self.id(id = nil)
  @id = id unless id.nil?
  @id
end

.invoke_callbacks(event, attribute) ⇒ Object

invoke callbacks registered for the specified event


174
175
176
177
178
179
# File 'lib/users/attribute.rb', line 174

def self.invoke_callbacks(event, attribute)
  @callbacks ||= {}
  @callbacks[event].each { |cb|
    cb.call attribute
  } if @callbacks.has_key?(event)
end

.multiplier(multiplier = nil) ⇒ Object

progression difficulty, amount multiplied by level to increase the difficulty of progressing to the next level


149
150
151
152
# File 'lib/users/attribute.rb', line 149

def self.multiplier(multiplier = nil)
  @multiplier = multiplier unless multiplier.nil?
  @multiplier
end

.requirements(requirements = nil) ⇒ Object

array of requirements needed by this attribute


155
156
157
158
# File 'lib/users/attribute.rb', line 155

def self.requirements(requirements = nil)
  @requirements = requirements unless requirements.nil?
  @requirements
end