Permalink
Browse files

DRYed up the OpenCongressObjects by moving their initialize into the …

…parent
  • Loading branch information...
1 parent de4a237 commit 9fb1c58afccbbbb7ff67f145d0fa2fcded6db6d4 @NateBarnes committed Jun 21, 2011
View
7 lib/gov_kit/open_congress.rb
@@ -13,6 +13,13 @@ module GovKit::OpenCongress
autoload :PersonStat, 'gov_kit/open_congress/person_stat'
class OpenCongressObject
+
+ def initialize(params)
+ params.each do |key, value|
+ key = key.to_sym if RUBY_VERSION[0,3] == "1.9"
+ instance_variable_set("@#{key}", value) if Person.instance_methods.include? key.to_sym
+ end
+ end
def self.construct_url(api_method, params)
url = nil
View
6 lib/gov_kit/open_congress/bill.rb
@@ -3,12 +3,6 @@ module OpenCongress
class Bill < OpenCongressObject
attr_accessor :bill_type, :id, :introduced, :last_speech, :last_vote_date, :last_vote_roll, :last_vote_where, :last_action, :number, :plain_language_summary, :session, :sponsor, :co_sponsors, :title_full_common, :status, :most_recent_actions, :bill_titles, :recent_blogs, :recent_news, :ident
- def initialize(params)
- params.each do |key, value|
- instance_variable_set("@#{key}", value) if Bill.instance_methods.include? key
- end
- end
-
def ident
"#{session}-#{bill_type}#{number}"
end
View
8 lib/gov_kit/open_congress/blog_post.rb
@@ -5,14 +5,6 @@ class BlogPost < OpenCongressObject
attr_accessor :title, :date, :url, :source_url, :excerpt, :source, :average_rating
-
- def initialize(params)
- params.each do |key, value|
- instance_variable_set("@#{key}", value) if BlogPost.instance_methods.include? key
- end
- end
-
-
end
end
View
8 lib/gov_kit/open_congress/news_post.rb
@@ -4,14 +4,6 @@ module OpenCongress
class NewsPost < OpenCongressObject
attr_accessor :title, :date, :url, :source_url, :excerpt, :source, :average_rating
-
-
- def initialize(params)
- params.each do |key, value|
- instance_variable_set("@#{key}", value) if NewsPost.instance_methods.include? key
- end
- end
-
end
View
7 lib/gov_kit/open_congress/person.rb
@@ -8,13 +8,6 @@ class Person < OpenCongressObject
:youtube_id, :oc_user_comments, :oc_users_tracking, :abstains_percentage, :with_party_percentage, :recent_news,
:recent_blogs, :person_stats
- def initialize(params)
- params.each do |key, value|
- key = key.to_sym if RUBY_VERSION[0,3] == "1.9"
- instance_variable_set("@#{key}", value) if Person.instance_methods.include? key.to_sym
- end
- end
-
def self.find(params)
url = construct_url("people", params)
View
8 lib/gov_kit/open_congress/person_stat.rb
@@ -3,14 +3,6 @@ module OpenCongress
class PersonStat < OpenCongressObject
attr_accessor :votes_most_often_with_id, :opposing_party_votes_most_often_with_id, :votes_least_often_with_id, :same_party_votes_least_often_with_id, :party_votes_percentage, :abstains_percentage, :abstains_percentage_rank, :party_votes_percentage_rank, :sponsored_bills, :cosponsored_bills, :abstains, :sponsored_bills_passed_rank, :cosponsored_bills_passed_rank, :sponsored_bills_passed, :cosponsored_bills_passed, :sponsored_bills_rank, :cosponsored_bills_rank
-
-
- def initialize(params)
- params.each do |key, value|
- instance_variable_set("@#{key}", value) if PersonStat.instance_methods.include? key.to_sym
- end
- end
-
end
View
8 lib/gov_kit/open_congress/roll_call.rb
@@ -4,13 +4,7 @@ class RollCall < OpenCongressObject
attr_accessor :abstains, :presents, :roll_type, :title, :question, :republican_position, :democratic_position,
:amendment_id, :ayes, :nays, :bill, :date, :number, :id, :required, :where
-
- def initialize(params)
- params.each do |key, value|
- instance_variable_set("@#{key}", value) if RollCall.instance_methods.include? key
- end
- end
-
+
end
end
end
View
5 lib/gov_kit/open_congress/roll_call_comparison.rb
@@ -5,10 +5,7 @@ class RollCallComparison < OpenCongressObject
attr_accessor :roll_call, :person1, :person2
def initialize(params)
- params.each do |key, value|
- instance_variable_set("@#{key}", value) if RollCallComparison.instance_methods.include? key
- end
-
+ super
set_people
set_roll_call
View
4 lib/gov_kit/open_congress/voting_comparison.rb
@@ -7,9 +7,7 @@ class VotingComparison < OpenCongressObject
:other_votes
def initialize(params)
- params.each do |key, value|
- instance_variable_set("@#{key}", value) if VotingComparison.instance_methods.include? key
- end
+ super
set_people
set_votes

0 comments on commit 9fb1c58

Please sign in to comment.