public
Last active

  • Download Gist
uscode.rb
Ruby
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
class USCode
SEARCH_ENDPOINT = "http://uscode.house.gov/uscode-cgi/fastweb.exe?search"
@@search_params = {
:view => "uscview",
:db2 => "t01t04" ,
:db3 => "t05t08" ,
:db4 => "t09t12" ,
:db5 => "t13t16" ,
:db6 => "t17t20" ,
:db7 => "t21t25" ,
:db8 => "t26t28" ,
:db9 => "t29t32" ,
:db10 => "t33t36" ,
:db11 => "t37t40" ,
:db12 => "t41t42" ,
:db13 => "t43t44" ,
:db14 => "t45t48" ,
:db15 => "t49t50" ,
:db16 => "usclass",
:db17 => "uscnst" ,
:db18 => "usctbls",
:query => "" ,
:query0 => '' , # title
:query1 => '' , # section
:query3 => '' ,
:query11 => '' ,
:query4 => '' ,
:query6 => '' ,
:query5 => '' ,
:query7 => '' ,
:query8 => '' ,
:query9 => '' ,
:query_rule => "(($query)) [ AND ((($query0)) ADJ USC):CITE][ AND (USC w/10 (($query1))):CITE] [AND (SUBTITLE ADJ (($query3))):EXPCITE] [AND (CHAPTER ADJ (($query4))):EXPCITE] [AND (SUBCHAPTER ADJ (($query5))):EXPCITE] [AND (PART ADJ (($query6))):EXPCITE] [AND (SUBPART ADJ (($query7))):EXPCITE] [AND (RULE* ADJ (($query8))):CITE] [AND (FORM* ADJ (($query9))):CITE] [AND (($query10)):CITE] [AND (DIVISION ADJ (($query11))):EXPCITE]",
:operation => "simplesearch",
:numresults => 100
}
 
attr_reader :name_of_law
# USCode.new('42 USC 3789g')
def initialize(standard_statute)
standard_statute =~ /^(\d+) USC ([\dA-Za-z-]+)/
@@search_params[:query0] = @title = $1
@@search_params[:query1] = @section = $2
end
def search
return unless @title && @section
html = Nokogiri::HTML(RestClient.post(SEARCH_ENDPOINT, @@search_params))
result = html.css('pre').text
result =~ (/Sec. #{@section}\. (.+)?(?:\n|$)/)
@name_of_law = $1 ? $1.strip : nil
end
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.