Class: Catobills::Bill

Inherits:
Object
  • Object
show all
Defined in:
lib/catobills/bill.rb

Constant Summary collapse

FILTER_LIST =
['Commission', 'Board', 'Secretary', 'Department', 'Administrator', 'Administration', 'House', 'Senate', 'Director', 'Advisory Committee', 'Task Force', 
"Secretary's", "Under Secretary", "Administrator's", "Board's", "Service", "Department of State's", "CSCC's", "Bureau", "Inspector General of the Office", "Office",
"Commissioner", "Assistant Secretary", "Comptroller General"]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Bill

Returns a new instance of Bill.



10
11
12
13
14
# File 'lib/catobills/bill.rb', line 10

def initialize(params={})
  params.each_pair do |k,v|
    instance_variable_set("@#{k}", v)
  end
end

Instance Attribute Details

#actsObject (readonly)

Returns the value of attribute acts.



4
5
6
# File 'lib/catobills/bill.rb', line 4

def acts
  @acts
end

#bill_bodyObject (readonly)

Returns the value of attribute bill_body.



4
5
6
# File 'lib/catobills/bill.rb', line 4

def bill_body
  @bill_body
end

#bill_numberObject (readonly)

Returns the value of attribute bill_number.



4
5
6
# File 'lib/catobills/bill.rb', line 4

def bill_number
  @bill_number
end

#bill_typeObject (readonly)

Returns the value of attribute bill_type.



4
5
6
# File 'lib/catobills/bill.rb', line 4

def bill_type
  @bill_type
end

#congressObject (readonly)

Returns the value of attribute congress.



4
5
6
# File 'lib/catobills/bill.rb', line 4

def congress
  @congress
end

#federal_bodiesObject (readonly)

Returns the value of attribute federal_bodies.



4
5
6
# File 'lib/catobills/bill.rb', line 4

def federal_bodies
  @federal_bodies
end

#versionObject (readonly)

Returns the value of attribute version.



4
5
6
# File 'lib/catobills/bill.rb', line 4

def version
  @version
end

Class Method Details

.array_count(array) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/catobills/bill.rb', line 50

def self.array_count(array)
  h = Hash.new(0)
  array.each do |v|
    h[v] += 1
  end
  h
end

.find(congress, bill_number, bill_type, version) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/catobills/bill.rb', line 22

def self.find(congress, bill_number, bill_type, version)
  url = "http://deepbills.cato.org/api/1/bill?congress=#{congress}&billnumber=#{bill_number}&billtype=#{bill_type}&billversion=#{version}"
  response = HTTParty.get(url)
  bill = Oj.load(response.body)
  bill_body = Ox.load(bill['billbody'])

  self.new(
    bill_number:    bill['billnumber'],
    bill_body:      bill_body,
    version:        bill['billversion'],
    congress:       bill['congress'],
    bill_type:      bill['billtype'],
    federal_bodies: self.populate_federal_bodies(bill_body),
    acts:           self.populate_acts(bill_body)
  )
end

.find_by_slug(congress, bill_slug) ⇒ Object



16
17
18
19
20
# File 'lib/catobills/bill.rb', line 16

def self.find_by_slug(congress, bill_slug)
  m = /([a-z]*)([0-9]*)/.match(bill_slug)
  version = m[1][0] == 'h' ? 'ih' : 'is'
  find(congress, m[2], m[1], version)
end

.populate_acts(bill_body) ⇒ Object



39
40
41
42
# File 'lib/catobills/bill.rb', line 39

def self.populate_acts(bill_body)
  results = bill_body.locate('legis-body/*/cato:entity-ref').select{|ref| ref['entity-type'] == 'act'}
  array_count(results.map{|ref| ref[:value].gsub(/\s+/, " ").strip.split('/').first}.compact.reject{|ref| ref[0] != ref[0].upcase}).reject{|ref| ref[0] == '('}.reject{|ref| ['Section', 'section', 'chapter', 'subsection'].any? {|s| ref.include?(s)}}
end

.populate_federal_bodies(bill_body) ⇒ Object

collects mentions of federal bodies, removing ‘Congress’, leadership offices, ‘Commission’, ‘Board’ and offices within agencies.



45
46
47
48
# File 'lib/catobills/bill.rb', line 45

def self.populate_federal_bodies(bill_body)
  results = bill_body.locate('legis-body/*/cato:entity-ref').select{|ref| ref['entity-type'] == 'federal-body'}
  array_count(results.flatten.reject{|ref| ref['entity-id'] == "0001"}.reject{|ref| ref['entity-parent-id'] == '0050'}.reject{|ref| ref['entity-parent-id'] == '0010'}.map{|ref| ref.text.gsub(/\s+/, " ").strip}.compact.reject{|x| FILTER_LIST.include?(x)})
end