Created
March 8, 2011 22:40
-
-
Save ashaw/861266 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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