class Propublica::Nonprofits::Organization::DynamicParser

Attributes

attributes[R]

Public Class Methods

fields(*fields) click to toggle source
# File lib/propublica/nonprofits/organization/dynamic_parser.rb, line 5
def self.fields(*fields)
  @fields = fields
  fields.each do |field|
    define_method field do
      vars = self.instance_variable_get("@attributes")
      vars.fetch(field.to_s) { raise_field_fetch_error(field) }
    end
  end
end
new(attributes) click to toggle source
# File lib/propublica/nonprofits/organization/dynamic_parser.rb, line 15
def initialize(attributes)
  @attributes = attributes || {}
end

Public Instance Methods

fields() click to toggle source
# File lib/propublica/nonprofits/organization/dynamic_parser.rb, line 19
def fields
  self.class.instance_variable_get("@fields")
end

Private Instance Methods

raise_field_fetch_error(field) click to toggle source
# File lib/propublica/nonprofits/organization/dynamic_parser.rb, line 27
def raise_field_fetch_error(field)
  class_name = self.class.to_s.split("::").last
  raise Propublica::Nonprofits::DataNotFetched,
    "#{class_name}##{field} not fetched from API. This may be due to an API error or because you tried to access a Basic property on the full results"
end