Class: OpenCongress::OCPerson

Inherits:
OpenCongressObject show all
Defined in:
lib/opencongress/person.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from OpenCongressObject

construct_url, hash2get, make_call, parse_supporting_results

Constructor Details

#initialize(params) ⇒ OCPerson

Returns a new instance of OCPerson.



12
13
14
15
16
# File 'lib/opencongress/person.rb', line 12

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

Instance Attribute Details

#abstains_percentageObject

Returns the value of attribute abstains_percentage.



6
7
8
# File 'lib/opencongress/person.rb', line 6

def abstains_percentage
  @abstains_percentage
end

#bioguideidObject

Returns the value of attribute bioguideid.



6
7
8
# File 'lib/opencongress/person.rb', line 6

def bioguideid
  @bioguideid
end

#birthdayObject

Returns the value of attribute birthday.



6
7
8
# File 'lib/opencongress/person.rb', line 6

def birthday
  @birthday
end

#districtObject

Returns the value of attribute district.



6
7
8
# File 'lib/opencongress/person.rb', line 6

def district
  @district
end

#emailObject

Returns the value of attribute email.



6
7
8
# File 'lib/opencongress/person.rb', line 6

def email
  @email
end

#firstnameObject

Returns the value of attribute firstname.



6
7
8
# File 'lib/opencongress/person.rb', line 6

def firstname
  @firstname
end

#genderObject

Returns the value of attribute gender.



6
7
8
# File 'lib/opencongress/person.rb', line 6

def gender
  @gender
end

#idObject

Returns the value of attribute id.



6
7
8
# File 'lib/opencongress/person.rb', line 6

def id
  @id
end

#lastnameObject

Returns the value of attribute lastname.



6
7
8
# File 'lib/opencongress/person.rb', line 6

def lastname
  @lastname
end

#metavid_idObject

Returns the value of attribute metavid_id.



6
7
8
# File 'lib/opencongress/person.rb', line 6

def metavid_id
  @metavid_id
end

#middlenameObject

Returns the value of attribute middlename.



6
7
8
# File 'lib/opencongress/person.rb', line 6

def middlename
  @middlename
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/opencongress/person.rb', line 6

def name
  @name
end

#nicknameObject

Returns the value of attribute nickname.



6
7
8
# File 'lib/opencongress/person.rb', line 6

def nickname
  @nickname
end

#oc_user_commentsObject

Returns the value of attribute oc_user_comments.



6
7
8
# File 'lib/opencongress/person.rb', line 6

def oc_user_comments
  @oc_user_comments
end

#oc_users_trackingObject

Returns the value of attribute oc_users_tracking.



6
7
8
# File 'lib/opencongress/person.rb', line 6

def oc_users_tracking
  @oc_users_tracking
end

#osidObject

Returns the value of attribute osid.



6
7
8
# File 'lib/opencongress/person.rb', line 6

def osid
  @osid
end

#partyObject

Returns the value of attribute party.



6
7
8
# File 'lib/opencongress/person.rb', line 6

def party
  @party
end

#person_statsObject

Returns the value of attribute person_stats.



6
7
8
# File 'lib/opencongress/person.rb', line 6

def person_stats
  @person_stats
end

#recent_blogsObject

Returns the value of attribute recent_blogs.



6
7
8
# File 'lib/opencongress/person.rb', line 6

def recent_blogs
  @recent_blogs
end

#recent_newsObject

Returns the value of attribute recent_news.



6
7
8
# File 'lib/opencongress/person.rb', line 6

def recent_news
  @recent_news
end

#religionObject

Returns the value of attribute religion.



6
7
8
# File 'lib/opencongress/person.rb', line 6

def religion
  @religion
end

#stateObject

Returns the value of attribute state.



6
7
8
# File 'lib/opencongress/person.rb', line 6

def state
  @state
end

#titleObject

Returns the value of attribute title.



6
7
8
# File 'lib/opencongress/person.rb', line 6

def title
  @title
end

#unaccented_nameObject

Returns the value of attribute unaccented_name.



6
7
8
# File 'lib/opencongress/person.rb', line 6

def unaccented_name
  @unaccented_name
end

#urlObject

Returns the value of attribute url.



6
7
8
# File 'lib/opencongress/person.rb', line 6

def url
  @url
end

#user_approvalObject

Returns the value of attribute user_approval.



6
7
8
# File 'lib/opencongress/person.rb', line 6

def user_approval
  @user_approval
end

#with_party_percentageObject

Returns the value of attribute with_party_percentage.



6
7
8
# File 'lib/opencongress/person.rb', line 6

def with_party_percentage
  @with_party_percentage
end

#youtube_idObject

Returns the value of attribute youtube_id.



6
7
8
# File 'lib/opencongress/person.rb', line 6

def youtube_id
  @youtube_id
end

Class Method Details

.all_where(params) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/opencongress/person.rb', line 18

def self.all_where(params)

  url = construct_url("people", params)
  if (result = make_call(url))
    people = parse_results(result)
    return people
  else
    nil
  end

end

.compare(person1, person2) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/opencongress/person.rb', line 30

def self.compare(person1, person2)
  url = "#{OC_BASE}person/compare.json?person1=#{person1.id}&person2=#{person2.id}"
  if (result = make_call(url))
    comparison = OCVotingComparison.new(result["comparison"])
  else
    nil
  end
  
end

.most_blogged_representatives_this_weekObject



76
77
78
79
80
81
82
83
84
85
86
# File 'lib/opencongress/person.rb', line 76

def self.most_blogged_representatives_this_week

  url = construct_url("most_blogged_representatives_this_week", {})
  if (result = make_call(url))
    people = parse_results(result)
    return people
  else
    nil
  end

end

.most_blogged_senators_this_weekObject



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/opencongress/person.rb', line 64

def self.most_blogged_senators_this_week

  url = construct_url("most_blogged_senators_this_week", {})
  if (result = make_call(url))
    people = parse_results(result)
    return people
  else
    nil
  end

end

.parse_results(result) ⇒ Object



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/opencongress/person.rb', line 112

def self.parse_results(result)

    people = []
    result.each do |person|
      
      these_recent_blogs = person["recent_blogs"]
      blogs = []
      these_recent_blogs.each do |trb|
        blogs << OCBlogPost.new(trb)
      end

      person["recent_blogs"] = blogs


      these_recent_news = person["recent_news"]
      news = []
      these_recent_news.each do |trb|
        news << OCNewsPost.new(trb)
      end
      
      person["person_stats"] = OCPersonStat.new(person["person_stats"]) if person["person_stats"]
      
      person["recent_news"] = news
      
      people << OCPerson.new(person)
    end      
    
    people
        
end

.representatives_most_in_the_news_this_weekObject



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/opencongress/person.rb', line 52

def self.representatives_most_in_the_news_this_week

  url = construct_url("representatives_most_in_the_news_this_week", {})
  if (result = make_call(url))
    people = parse_results(result)
    return people
  else
    nil
  end

end

.senators_most_in_the_news_this_weekObject



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/opencongress/person.rb', line 40

def self.senators_most_in_the_news_this_week

  url = construct_url("senators_most_in_the_news_this_week", {})
  if (result = make_call(url))
    people = parse_results(result)
    return people
  else
    nil
  end

end

Instance Method Details

#opencongress_users_opposing_person_are_alsoObject



98
99
100
101
102
103
104
105
106
# File 'lib/opencongress/person.rb', line 98

def opencongress_users_opposing_person_are_also
  url = OCPerson.construct_url("opencongress_users_opposing_person_are_also/#{id}", {})
  if (result = OCPerson.make_call(url))
    people = OCPerson.parse_supporting_results(result)
    return people
  else
    nil
  end
end

#opencongress_users_supporting_person_are_alsoObject



88
89
90
91
92
93
94
95
96
# File 'lib/opencongress/person.rb', line 88

def opencongress_users_supporting_person_are_also
  url = OCPerson.construct_url("opencongress_users_supporting_person_are_also/#{id}", {})
  if (result = OCPerson.make_call(url))
    people = OCPerson.parse_supporting_results(result)
    return people
  else
    nil
  end
end