Sha256: 2e9ddcccda69e4141f2c807e19c7ea7ec8c9290f3d68440c54df579d01b09b03

Contents?: true

Size: 769 Bytes

Versions: 12

Compression:

Stored size: 769 Bytes

Contents

module Census
  class DataType
    attr_accessor :name
    attr_accessor :sql_transform
    attr_accessor :format_data
    attr_accessor :validate_data

    @@data_types = []

    def self.all
      @@data_types
    end
    
    def self.define(name, options = {})
      @@data_types << DataType.new(name, options)
    end
    
    def self.find(name)
      @@data_types.select {|dt| dt.name == name}.try(:first)
    end
    
    def initialize(name, options)
      @name = name
      @sql_transform  = options[:sql_transform] || lambda {|column_name| "#{column_name}"}
      @format_data    = options[:format_data]   || lambda {|data| data}
      @validate_data  = options[:validate_data] || lambda {|data| nil}
    end
    
    def to_s
      @name
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
census-0.5.2 lib/census/data_type.rb
census-0.5.0 lib/census/data_type.rb
census-0.4.4 lib/census/data_type.rb
census-0.4.3 lib/census/data_type.rb
census-0.4.2 lib/census/data_type.rb
census-0.4.1 lib/census/data_type.rb
census-0.4.0 lib/census/data_type.rb
census-0.3.1 lib/census/data_type.rb
census-0.3.0 lib/census/data_type.rb
census-0.2.1 lib/census/data_type.rb
census-0.2.0 lib/census/data_type.rb
census-0.1.0 lib/census/data_type.rb