Sha256: d338eb5d672587bc38ca1f3e6d1e97689a2feba9e8808ee6fb83c93e8987d500

Contents?: true

Size: 1.37 KB

Versions: 1

Compression:

Stored size: 1.37 KB

Contents

module Helper
  require 'open-uri'
  
  SERVICE_KIND_HASH = {
    "0" => :electricity,
    "1" => :gas,
    "2" => :water,
    "3" => :time,
    "4" => :heat,
    "5" => :refuse,
    "6" => :sewerage,
    "7" => :rates,
    "8" => :tv_licence,
    "9" => :internet   
  }
  
  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
  
  def self.pluralize(name)
    name = name.to_s.sub(/(y)$/i, 'ie')
    name += 's'
  end
  
  # from Rails http://apidock.com/rails/v4.0.2/ActiveSupport/Inflector/underscore
   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
	
	class Rule
    attr_accessor :attr_name, :xpath, :type

    def initialize(attr_name, xpath, type)
      @attr_name = attr_name
      @xpath = xpath
      @type = type
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
greenbutton-0.0.1 lib/greenbutton/helpers.rb