-
Notifications
You must be signed in to change notification settings - Fork 4
/
csv.rb
108 lines (86 loc) · 2.69 KB
/
csv.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
require 'csv'
def csv?
(params[:format] == 'csv') or (params[:captures] and (params[:captures][0] == '.csv'))
end
def csv_out(filename)
response['Content-Type'] = 'text/csv'
response['Content-Disposition'] = "attachment;filename=#{filename}"
end
def members_to_csv(members)
csv_out 'members.csv'
CSV.generate do |csv|
csv << [
"Name", "Phone", "Building", "Room",
"Bioguide ID", "Title", "First Name", "Last Name", "Suffix",
"Party", "State", "District", "In Office"
]
members.each do |member|
leg = member['member']
csv << [
member.name, member.phone, member.building, member.room,
leg['bioguide_id'], leg['title'], leg['firstname'], leg['lastname'], leg['name_suffix'],
leg['party'], leg['state'], leg['district'], leg['in_office']
]
end
end
end
def committees_to_csv(committees)
csv_out 'committees.csv'
CSV.generate do |csv|
csv << [
"Name", "Phone", "Building", "Room",
"Committee ID"
]
committees.each do |committee|
csv << [
committee.name, committee.phone, committee.building, committee.room,
committee['committee']['id']
]
end
end
end
def offices_to_csv(offices)
csv_out 'offices.csv'
CSV.generate do |csv|
csv << [
"Name", "Phone", "Building", "Room"
]
offices.each do |office|
csv << [office.name, office.phone, office.building, office.room]
end
end
end
def office_to_csv(office, positions)
names = {'committee' => 'committee', 'member' => 'member', 'other' => 'office'}
csv_out "#{names[office.office_type]}.csv"
CSV.generate do |csv|
csv << [
"Office", "Quarter", "Staffer", "Title"
]
positions.each do |position|
csv << [position['office']['name'], position['quarter'], position['staffer']['name'], position['title']['name']]
end
end
end
def staffer_to_csv(staffer, positions)
csv_out 'staffer.csv'
CSV.generate do |csv|
csv << [
"Staffer", "Quarter", "Title", "Office", "Phone", "Building", "Room"
]
positions.each do |position|
csv << [staffer.name, position['quarter'], position['title']['name'], position['office']['name'], position['office']['phone'], position['office']['building'], position['office']['room']]
end
end
end
def positions_to_csv(positions)
csv_out 'positions.csv'
CSV.generate do |csv|
csv << [
"Staffer", "Quarter", "Title", "Office", "Phone", "Building", "Room"
]
positions.each do |position|
csv << [position['staffer']['name'], position['quarter'], position['title']['name'], position['office']['name'], position['office']['phone'], position['office']['building'], position['office']['room']]
end
end
end