Class: Sunlight::Lobbyist
Constant Summary
Constants inherited from Base
Base::API_FORMAT, Base::API_URL
Instance Attribute Summary collapse
-
#filings ⇒ Object
Returns the value of attribute filings.
-
#firstname ⇒ Object
Returns the value of attribute firstname.
-
#fuzzy_score ⇒ Object
Returns the value of attribute fuzzy_score.
-
#lastname ⇒ Object
Returns the value of attribute lastname.
-
#middlename ⇒ Object
Returns the value of attribute middlename.
-
#official_position ⇒ Object
Returns the value of attribute official_position.
-
#suffix ⇒ Object
Returns the value of attribute suffix.
Class Method Summary collapse
-
.search_by_name(name, threshold = 0.9, year = Time.now.year) ⇒ Object
Fuzzy name searching of lobbyists.
Instance Method Summary collapse
-
#initialize(params) ⇒ Lobbyist
constructor
Takes in a hash where the keys are strings (the format passed in by the JSON parser).
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
#filings ⇒ Object
Returns the value of attribute filings.
4 5 6 |
# File 'lib/sunlight/lobbyist.rb', line 4 def filings @filings end |
#firstname ⇒ Object
Returns the value of attribute firstname.
4 5 6 |
# File 'lib/sunlight/lobbyist.rb', line 4 def firstname @firstname end |
#fuzzy_score ⇒ Object
Returns the value of attribute fuzzy_score.
4 5 6 |
# File 'lib/sunlight/lobbyist.rb', line 4 def fuzzy_score @fuzzy_score end |
#lastname ⇒ Object
Returns the value of attribute lastname.
4 5 6 |
# File 'lib/sunlight/lobbyist.rb', line 4 def lastname @lastname end |
#middlename ⇒ Object
Returns the value of attribute middlename.
4 5 6 |
# File 'lib/sunlight/lobbyist.rb', line 4 def middlename @middlename end |
#official_position ⇒ Object
Returns the value of attribute official_position.
4 5 6 |
# File 'lib/sunlight/lobbyist.rb', line 4 def official_position @official_position end |
#suffix ⇒ Object
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 |