Sha256: 3a3c3556bb2a3d9eeec581450d718486a27475beb1bb2d610ba34fb0d3adc92b

Contents?: true

Size: 897 Bytes

Versions: 5

Compression:

Stored size: 897 Bytes

Contents

require 'enrichment_db/error'
require 'enrichment_db/version'

module EnrichmentDb
  module_function

  class DatumModel
    attr_accessor :attrs
    alias :to_hash :attrs

    # Define methods that retrieve the value from an initialized instance variable Hash, using the attribute as a key
    #
    # @overload self.lazy_attr_reader(attr)
    #   @param attr [Symbol]
    # @overload self.lazy_attr_reader(attrs)
    #   @param attrs [Array<Symbol>]
    def self.lazy_attr_reader(*attrs)
      attrs.each do |attribute|
        class_eval do
          define_method attribute do
            @attrs[attribute.to_s] || @attrs[attribute.to_sym]
          end
        end
      end
    end

    # Initializes a new Base object
    #
    # @param attrs [Hash]
    # @return [DatumModel]
    def initialize(attrs={})
      @attrs = attrs.dup
    end
  end
end

require 'enrichment_db/geo'
require 'db'

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
enrichment_db-0.1.4 lib/enrichment_db.rb
enrichment_db-0.1.3 lib/enrichment_db.rb
enrichment_db-0.1.2 lib/enrichment_db.rb
enrichment_db-0.1.1 lib/enrichment_db.rb
enrichment_db-0.1.0 lib/enrichment_db.rb