module Helper

Constants

SERVICE_KIND_HASH

Public Class Methods

pluralize(name) click to toggle source
# File lib/greenbutton/helpers.rb, line 35
def self.pluralize(name)
  name = name.to_s.sub(/(y)$/i, 'ie')
  name += 's'
end
translate(type, input_to_translate) click to toggle source
# File lib/greenbutton/helpers.rb, line 17
def self.translate(type, input_to_translate)
    if !input_to_translate.nil?
      case type
      when :ServiceKind
        translated = SERVICE_KIND_HASH[input_to_translate] || input_to_translate
      when :datetime
        translated = DateTime.parse(input_to_translate).to_time.utc
      when :unix_time
        translated = Time.at(input_to_translate.to_i).utc
      when :integer
        translated = input_to_translate.to_i
      else
        translated = input_to_translate
      end
      translated
    end
end
underscore(camel_cased_word) click to toggle source

from Rails apidock.com/rails/v4.0.2/ActiveSupport/Inflector/underscore

# File lib/greenbutton/helpers.rb, line 41
def self.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