require "date" module FBO::Parser::ParserHelper extend FBO::Parser::NoticeHandler protected # Get the date of the notice. # # @param text [String] the full text of the notice # @return [Date] the date that the notice was posted def date(text) date_string = simple_tag_contents(text, "DATE") Date.parse("#{ year(text) }#{ date_string }") end # Get the year from the notice or assume the current year. # # @param [text] the whole notice text # @return [Fixnum] the year of the notice def year(text) year_string = simple_tag_contents(text, "YEAR") "20#{ year_string }".to_i end # Get the zip code of the contracting office. # # @param text [String] the full text of the notice # @return [String] the zip code of the contracting office def zip(text) simple_tag_contents(text, "ZIP") end # Get the two-digit or single alphabetic code for classifying the notice. # # @param text [String] the full text of the notice # @return [String] the classification code as a string def classification_code(text) simple_tag_contents(text, "CLASSCOD") end # Get the NAICS code that should be referenced with this notice. # # @param text [String] the full text of the notice # @return [String] the relevant NAICS code def naics_code(text) simple_tag_contents(text, "NAICS") end # Get the agency name for this notice. # # @param text [String] the full text of the notice # @return [String] the name of the agency def agency(text) simple_tag_contents(text, "AGENCY") end # Get the agency office name for this notice. # # @param text [String] the full text of the notice # @return [String] the name of the agency office def office(text) simple_tag_contents(text, "OFFICE") end # Get the location of the office issuing the notice (often used for department). # # @param text [String] the full text of the notice # @return [String] the location text def location(text) simple_tag_contents(text, "LOCATION") end # Get the office address from which the notice is issued. # # @param text [String] the full text of the notice # @return [String] the office address def office_address(text) simple_tag_contents(text, "OFFADD") end # Get the subject of the notice. # # @param text [String] the full text of the notice # @return [String] the subject address def subject(text) simple_tag_contents(text, "SUBJECT") end # Get the solicitation number for the notice. # # @param text [String] the full text of the notice # @return [String] the solicitation number def solicitation_number(text) simple_tag_contents(text, "SOLNBR") end # Get the type of the related notice in the case of dependent notices. # # @param text [String] the full text of the notice # @return [String] the notice type def notice_type(text) simple_tag_contents(text, "NTYPE") end # Get the deadline for responding to the notice. # # @param text [String] the full text of the notice # @return [Date] the response date def response_date(text) date_string = simple_tag_contents(text, "RESPDATE") date_string ? Date.strptime(date_string, "%m%d%y") : nil end # Get the date when the notice will be archived. # # @param text [String] the full text of the notice # @return [Date] the archive date def archive_date(text) date_string = simple_tag_contents(text, "ARCHDATE") date_string ? Date.strptime(date_string, "%m%d%Y") : nil end # Get the contact information for responding to the notice. # # @param text [String] the full text of the notice # @return [String] the contact info def contact(text) simple_tag_contents(text, "CONTACT") end # Get the full description of the notice. # This implementation accounts for the fact that there may be more than one # DESC tag in the notice and that the one we want will be the first one. # # @param text [String] the full text of the notice # @return [String] the description def description(text) match = text.match(//) match2 = match.post_match.match(/<(?:#{ any_notice_tag })>/) prematch = match2.pre_match prematch ? prematch.strip : nil end # Get the link URL. # # @param text [String] the full text of the notice # @return [String] the URL def link_url(text) match = text.match(//) simple_tag_contents(match.post_match, "URL") if match end # Get the link description / text. # # @param text [String] the full text of the notice # @return [String] the link description def link_description(text) match = text.match(//) description(match.post_match) if match end # Get the contact email address. # # @param text [String] the full text of the notice # @return [String] the email address def email_address(text) match = text.match(//) simple_tag_contents(match.post_match, "(EMAIL|ADDRESS)") if match end # Get the contact email description (link text). # # @param text [String] the full text of the notice # @return [String] the email description def email_description(text) match = text.match(//) description(match.post_match) if match end # Get the set-aside identifier for the notice. # # @param text [String] the full text of the notice # @return [String] the set-aside def set_aside(text) simple_tag_contents(text, "SETASIDE") end # Get the address of the "place of performance". # # @param text [String] the full text of the notice # @return [String] the address def pop_address(text) simple_tag_contents(text, "POPADDRESS") end # Get the zip code of the "place of performance". # # @param text [String] the full text of the notice # @return [String] the zip code def pop_zip_code(text) simple_tag_contents(text, "POPZIP") end # Get the country of the "place of performance". # # @param text [String] the full text of the notice # @return [String] the country def pop_country(text) simple_tag_contents(text, "POPCOUNTRY") end # Get the award number with which the notice is associated. # # @param text [String] the full text of the notice # @return [String] the award number def award_number(text) simple_tag_contents(text, "AWDNBR") end # Get the amount of the award with which the notice is associated. # # @param text [String] the full text of the notice # @return [Float] the award amount (in dollars) def award_amount(text) amount_string = simple_tag_contents(text, "AWDAMT") amount_string.gsub(/[^\d\.]/, "").to_f end # Get the line number of the contract with which the award is associated. # # @param text [String] the full text of the notice # @return [String] the line number (which might not be a Fixnum) def line_number(text) simple_tag_contents(text, "LINENBR") end # Get the date of the award. # # @param text [String] the full text of the notice # @return [Date] the date that the award was given def award_date(text) date_string = simple_tag_contents(text, "AWDDATE") Date.strptime(date_string, "%m%d%y") end # Get the name of the awardee. # # @param text [String] the full text of the notice # @return [String] the awardee's name def awardee(text) simple_tag_contents(text, "AWARDEE") end # Get the DUNS number for the awardee. # # @param text [String] the full text of the notice # @return [String] the awardee's DUNS number def awardee_duns(text) simple_tag_contents(text, "AWARDEEDUNS") end # If the notice is a correction of a previous notice, return true; otherwise, false. # # @param text [String] the full text of the notice # @return [boolean] def correction?(text) correction_string = simple_tag_contents(text, "CORRECTION") if correction_string && correction_string =~ /^y/i return true end false end end