Sha256: bd411ea8d78b088ceae609eded34b35ec3b36a95e5f07d604e181c5fea7d1a4c

Contents?: true

Size: 1.8 KB

Versions: 2

Compression:

Stored size: 1.8 KB

Contents

EXPERIAN_LIB_DIR = File.dirname(__FILE__)
Dir["#{EXPERIAN_LIB_DIR}/element_numbers/*.rb"].each { |f| require(f) }

module Experian
  class DataDictionary
    def self.lookup(column, key)
      column = column.to_s.downcase.gsub(/\s+/, '')
      key = key.to_s.strip
      self.send("en_#{column}", key)
    end

    def self.column_name(column)
      column = column.to_s.downcase.gsub(/\s+/, '')
      self.send("en_#{column}_column_name")
    end

    def self.value_description(column)
      column = column.to_s.downcase.gsub(/\s+/, '')
      self.send("en_#{column}_value_description")
    end

    def self.description(column)
      column = column.to_s.downcase.gsub(/\s+/, '')
      self.send("en_#{column}_description")
    end

    def self.method_missing(method, *args, &block)
      method_parts = method.to_s.split('_')
      if (2..4) === method_parts.size and method_parts[0] == 'en'
        column = method_parts[1]
        if /^[0-9]{1,3}$/ =~ column
          letters = ''
          column = "%04d" % column
          #new_method = method_parts.size == 3 ? "en_#{column}_description".to_sym : "en_#{column}".to_sym
        elsif /[a-z]$/ =~ column
          letters = column.match(/[a-z]+$/)[0]
          column = "%04d" % column.to_i
          #new_method = method_parts.size == 3 ? "en_#{column}#{letters}_description".to_sym : "en_#{column}#{letters}".to_sym
        end

        method_parts.shift(2)
        method_sufix = method_parts.join('_')
        new_method = method_sufix.size > 0 ? "en_#{column}#{letters}_#{method_sufix}".to_sym : "en_#{column}#{letters}".to_sym

        if self.methods.include?(new_method)
          return self.send(new_method, *args, &block)
        else
          super(new_method, *args, &block)
        end
      else
        super(method, *args, &block)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
experian-data-dictionary-1.4.3 lib/experian.rb
experian-data-dictionary-1.4.2 lib/experian.rb