Class: Sunlight::Committee

Inherits:
Base
  • Object
show all
Defined in:
lib/sunlight/committee.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) ⇒ Committee


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/sunlight/committee.rb', line 7

def initialize(params)
  params.each do |key, value|

    case key

    when 'subcommittees'
      self.subcommittees = add_nodes('committee', Sunlight::Committee, value)

    when 'members'
      self.members = add_nodes('legislator', Sunlight::Legislator, value)

    else
      instance_variable_set("@#{key}", value) if Committee.instance_methods.map { |m| m.to_sym }.include? key.to_sym
    end
  end
end

Instance Attribute Details

#chamberObject

Returns the value of attribute chamber


5
6
7
# File 'lib/sunlight/committee.rb', line 5

def chamber
  @chamber
end

#idObject

Returns the value of attribute id


5
6
7
# File 'lib/sunlight/committee.rb', line 5

def id
  @id
end

#membersObject

Returns the value of attribute members


5
6
7
# File 'lib/sunlight/committee.rb', line 5

def members
  @members
end

#nameObject

Returns the value of attribute name


5
6
7
# File 'lib/sunlight/committee.rb', line 5

def name
  @name
end

#subcommitteesObject

Returns the value of attribute subcommittees


5
6
7
# File 'lib/sunlight/committee.rb', line 5

def subcommittees
  @subcommittees
end

Class Method Details

.all_for_chamber(chamber) ⇒ Object

Usage:

Sunlight::Committee.all_for_chamber("Senate") # or "House" or "Joint"

Returns:

An array of Committees in that chamber of Congress


60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/sunlight/committee.rb', line 60

def self.all_for_chamber(chamber)
  
  url = construct_url("committees.getList", {:chamber=> chamber})
  
  if (result = get_json_data(url))
    committees = []
    result["response"]["committees"].each do |committee|
      committees << Committee.new(committee["committee"])
    end
  else
    nil # appropriate params not found
  end
  
  committees
  
end

.get(id) ⇒ Object

Usage:

Sunlight::Committee.get("JSPR")     # returns a Committee

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

def self.get(id)

  url = construct_url("committees.get", {:id => id})
  
  if (result = get_json_data(url))
    committee = Committee.new(result["response"]["committee"])
  else
    nil # appropriate params not found
  end

end

Instance Method Details

#add_nodes(type, klass, values) ⇒ Object


28
29
30
31
32
# File 'lib/sunlight/committee.rb', line 28

def add_nodes(type, klass, values)
  values.each_with_object([]) do |value, arr|
    arr << klass.new(value[type])
  end
end

#load_membersObject


24
25
26
# File 'lib/sunlight/committee.rb', line 24

def load_members
  self.members = Sunlight::Committee.get(self.id).members
end