module Eol::Utils

Public Class Methods

camelize(word, uppercase_first_letter = true) click to toggle source
# File lib/eol/utils.rb, line 21
def self.camelize(word, uppercase_first_letter = true)
  if uppercase_first_letter
    word.to_s.gsub(%r{/\/(.?)/}) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
  else
    word[0] + Utils.camelize(word)[1..-1]
  end
end
collection_path(class_name) click to toggle source
# File lib/eol/utils.rb, line 17
def self.collection_path(class_name)
  (Utils.pluralize Utils.demodulize class_name).downcase
end
demodulize(class_name_in_module) click to toggle source
# File lib/eol/utils.rb, line 5
def self.demodulize(class_name_in_module)
  class_name_in_module.to_s.sub(/^.*::/, "")
end
modulize(class_name) click to toggle source
# File lib/eol/utils.rb, line 13
def self.modulize(class_name)
  "Eol::#{class_name}"
end
normalize_hash(hash) click to toggle source
# File lib/eol/utils.rb, line 41
def self.normalize_hash(hash)
  Hash[hash.map { |k, v| [Utils.normalize_hash_key(k), v] }] if hash
end
normalize_hash_key(key) click to toggle source
# File lib/eol/utils.rb, line 29
def self.normalize_hash_key(key)
  if key.is_a? String
    key = key.gsub(/::/, "/")
    key = key.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
    key = key.gsub(/([a-z\d])([A-Z])/, '\1_\2')
    key = key.tr("-", "_")
    key = key.downcase
    return key.to_sym
  end
  key
end
parse_key(key) click to toggle source
# File lib/eol/utils.rb, line 45
def self.parse_key(key)
  "VATCode" if key.casecmp "vat_code"
  Utils.camelize(key)
end
pluralize(word) click to toggle source
# File lib/eol/utils.rb, line 9
def self.pluralize(word)
  word.to_s.sub(/([^s])$/, '\1s')
end