Class: Starcraft2::Utils

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

Class Method Summary collapse

Class Method Details

.load(klass, options, class_map = {}, build_map = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/starcraft2/utils.rb', line 13

def self.load(klass, options, class_map = {}, build_map = {})
  options.each do |k, v|
    k = self.underscore(k.to_s)
    k = k.to_sym
    v = class_map[k].new(v) if class_map.keys.include?(k)
    v = build_map[k].build(v) if build_map.keys.include?(k)

    klass.send(:"#{k}=", v)
  end
end

.underscore(string) ⇒ Object



3
4
5
6
7
8
9
10
11
# File 'lib/starcraft2/utils.rb', line 3

def self.underscore(string)
  word = string.dup
  word.gsub!(/::/, '/')
  word.gsub!(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
  word.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
  word.tr!('-', '_')
  word.downcase!
  word
end