Module: RTurk::Utilities

Included in:
Requester
Defined in:
lib/rturk/utilities.rb

Instance Method Summary collapse

Instance Method Details

#camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/rturk/utilities.rb', line 3

def camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true)
  if first_letter_in_uppercase
    lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
  else
    lower_case_and_underscored_word.first + camelize(lower_case_and_underscored_word)[1..-1]
  end
end

#stringify_keys(ahash) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/rturk/utilities.rb', line 9

def stringify_keys(ahash)
  ahash = ahash.inject({}) do |options, (key, value)|
    options[(key.to_s rescue key) || key] = value
    options
  end
  ahash
end

#underscore(camel_cased_word) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/rturk/utilities.rb', line 25

def underscore(camel_cased_word)
  camel_cased_word.to_s.gsub(/::/, '/').
    gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
    gsub(/([a-z\d])([A-Z])/,'\1_\2').
    tr("-", "_").
    downcase
end