Sha256: e34bd6d9432697fff1a74763e064de825b55845c0a5a26365be6dadac74af587

Contents?: true

Size: 945 Bytes

Versions: 22

Compression:

Stored size: 945 Bytes

Contents

module RTurk::Utilities

  def camelize(phrase)
    phrase.gsub!(/^[a-z]|\_+[a-z]/) { |a| a.upcase }
    phrase.gsub!(/\_/, '')
    return phrase
  end

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

  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

  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

end

# TODO: Build an Nokogiri from_xml parser, should return a hash

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
rturk-2.6.0 lib/rturk/utilities.rb
rturk-2.5.2 lib/rturk/utilities.rb
rturk-2.5.0 lib/rturk/utilities.rb
rturk-2.4.1 lib/rturk/utilities.rb
rturk-2.4.0 lib/rturk/utilities.rb
rturk-2.3.6 lib/rturk/utilities.rb
rturk-2.3.5 lib/rturk/utilities.rb
rturk-2.3.4 lib/rturk/utilities.rb
rturk-2.3.3 lib/rturk/utilities.rb
rturk-2.3.2 lib/rturk/utilities.rb
rturk-2.3.1 lib/rturk/utilities.rb
rturk-2.3.0 lib/rturk/utilities.rb
rturk-2.2.1 lib/rturk/utilities.rb
rturk-2.2.0 lib/rturk/utilities.rb
rturk-2.1.1 lib/rturk/utilities.rb
rturk-2.1.0 lib/rturk/utilities.rb
rturk-2.0.5 lib/rturk/utilities.rb
rturk-2.0.4 lib/rturk/utilities.rb
rturk-2.0.3 lib/rturk/utilities.rb
rturk-2.0.2 lib/rturk/utilities.rb