module OpenStates::Model::ClassMethods

Public Instance Methods

api_method() click to toggle source
# File lib/openstates/model.rb, line 42
def api_method
  raise NotImplementedError
end
find(id) click to toggle source
# File lib/openstates/model.rb, line 24
def find(id)
  return if !id

  id_hash = {}
  id_hash[id_key] = id
  response = OpenStates.send(api_method, id_hash)

  from_hash(response)
end
from_hash(hash) { |instance| ... } click to toggle source
# File lib/openstates/model.rb, line 8
def from_hash(hash)
  instance = new
  instance.populate_from_hash!(hash)
  yield instance if block_given?
  instance
end
hash_attr_accessor(*symbols) click to toggle source
# File lib/openstates/model.rb, line 15
def hash_attr_accessor(*symbols)
  attr_writer(*symbols)
  symbols.each do |symbol|
    define_method(symbol) do
      instance_variable_get("@#{symbol}")
    end
  end
end
id_key() click to toggle source
# File lib/openstates/model.rb, line 46
def id_key
  raise NotImplementedError
end
where(options = {}) click to toggle source
# File lib/openstates/model.rb, line 34
def where(options = {})
  return [] if options.empty?

  OpenStates.send(api_method, options).map do |leg_hash|
    from_hash(leg_hash)
  end
end