Module: Labor::Helpers

Included in:
Ability, Worker
Defined in:
lib/labor/helpers.rb

Instance Method Summary collapse

Instance Method Details

#classify(word) ⇒ Object



3
4
5
# File 'lib/labor/helpers.rb', line 3

def classify(word)
  word.split('-').each { |part| part[0] = part[0].chr.upcase }.join
end

#constantize(camel_cased_word) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/labor/helpers.rb', line 7

def constantize(camel_cased_word)
  camel_cased_word = camel_cased_word.to_s

  if camel_cased_word.include?('-')
    camel_cased_word = classify(camel_cased_word)
  end

  names = camel_cased_word.split('::')
  names.shift if names.empty? || names.first.empty?

  constant = Object
  names.each do |name|
    constant = constant.const_get(name) || constant.const_missing(name)
  end
  constant
end

#log(str) ⇒ Object



24
25
26
27
28
# File 'lib/labor/helpers.rb', line 24

def log(str)
  if Labor.verbose
    puts "#{Time.now.strftime('%I:%M:%S %d-%m-%Y')}: #{str}"
  end
end