Class: Sunlight::Lobbyist

Inherits:
Base
  • Object
show all
Defined in:
lib/sunlight/lobbyist.rb

Constant Summary

Constants inherited from Base

Base::API_FORMAT, Base::API_URL

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

api_key, api_key=, construct_url, get_json_data, hash2get

Constructor Details

#initialize(params) ⇒ Lobbyist

Takes in a hash where the keys are strings (the format passed in by the JSON parser)



9
10
11
12
13
# File 'lib/sunlight/lobbyist.rb', line 9

def initialize(params)
  params.each do |key, value|    
    instance_variable_set("@#{key}", value) if Lobbyist.instance_methods.include? key
  end
end

Instance Attribute Details

#filingsObject

Returns the value of attribute filings.



4
5
6
# File 'lib/sunlight/lobbyist.rb', line 4

def filings
  @filings
end

#firstnameObject

Returns the value of attribute firstname.



4
5
6
# File 'lib/sunlight/lobbyist.rb', line 4

def firstname
  @firstname
end

#fuzzy_scoreObject

Returns the value of attribute fuzzy_score.



4
5
6
# File 'lib/sunlight/lobbyist.rb', line 4

def fuzzy_score
  @fuzzy_score
end

#lastnameObject

Returns the value of attribute lastname.



4
5
6
# File 'lib/sunlight/lobbyist.rb', line 4

def lastname
  @lastname
end

#middlenameObject

Returns the value of attribute middlename.



4
5
6
# File 'lib/sunlight/lobbyist.rb', line 4

def middlename
  @middlename
end

#official_positionObject

Returns the value of attribute official_position.



4
5
6
# File 'lib/sunlight/lobbyist.rb', line 4

def official_position
  @official_position
end

#suffixObject

Returns the value of attribute suffix.



4
5
6
# File 'lib/sunlight/lobbyist.rb', line 4

def suffix
  @suffix
end

Class Method Details

.search_by_name(name, threshold = 0.9, year = Time.now.year) ⇒ Object

Fuzzy name searching of lobbyists. Returns possible matching Lobbyists along with a confidence score. Confidence scores below 0.8 mean the lobbyist should not be used.

See the API documentation:

wiki.sunlightlabs.com/index.php/Lobbyists.search

Returns:

An array of Lobbyists, with the fuzzy_score set as an attribute

Usage:

lobbyists = Lobbyist.search("Nisha Thompsen")
lobbyists = Lobbyist.search("Michael Klein", 0.95, 2007)


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/sunlight/lobbyist.rb', line 33

def self.search_by_name(name, threshold=0.9, year=Time.now.year)

  url = construct_url("lobbyists.search", :name => name, :threshold => threshold, :year => year)
  
  if (results = get_json_data(url))
    lobbyists = []
    results["response"]["results"].each do |result|
      if result
        lobbyist = Lobbyist.new(result["result"]["lobbyist"])
        fuzzy_score = result["result"]["score"]

        if threshold.to_f < fuzzy_score.to_f
          lobbyist.fuzzy_score = fuzzy_score.to_f
          lobbyists << lobbyist
        end
      end
    end

    if lobbyists.empty?
      nil
    else
      lobbyists
    end
  
  else
    nil
  end
end