Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@esagara
Forked from ashaw/uscode.rb
Created February 19, 2014 22:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save esagara/9102770 to your computer and use it in GitHub Desktop.
Save esagara/9102770 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment