Sha256: e15212065f9b0099b04b08708a1fb02f3c408f170ffe6195ce917bdd8a81516e

Contents?: true

Size: 750 Bytes

Versions: 1

Compression:

Stored size: 750 Bytes

Contents

module DataDotGov
  module Objects
    DEFAULT_ALIASES = {
      'COUNTYNM' => 'county_name',
      'STABBR' => 'state',
      'WEBADDR' => 'web_address',
      'LONGITUD' => 'longitude',
      'LATITUDE' => 'latitude',
      'ZIP' => 'zip_code'
    }

    class Base
      def initialize(attributes = {}, aliases = {})
        aliases = DEFAULT_ALIASES.merge(aliases)
        attributes.each do |key, value|
          # https://github.com/ohler55/oj#options
          key = aliases[key] if aliases[key]
          instance_variable_set(:"@#{key}", value)
        end
      end

      def method_missing(*args)
        name = args.shift
        instance_variable_get("@#{name}") || instance_variable_get("@#{name.upcase}")
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
DataDotGov-0.1.0 lib/DataDotGov/objects/base.rb