ietf

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 0052851b5315ed3e678b7be1f540b991b6a4ab33
parent cf8cdbded4410bd7c2ca0f0fbcf84b3da5ddbcb9
Author: cy6erlion <50733658+cy6erlion@users.noreply.github.com>
Date:   Mon,  8 Feb 2021 18:50:34 +0200

Merge pull request #9 from nickrtorres/master

include final RFC during scrape
Diffstat:
Msrc/fetch.rs | 72+++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------------
1 file changed, 55 insertions(+), 17 deletions(-)

diff --git a/src/fetch.rs b/src/fetch.rs @@ -12,26 +12,64 @@ pub fn rfc(sn: u32) -> Result<String, minreq::Error> { Ok(String::from(response.as_str()?)) } -// TODO: fix bug causing not to return the last RFC pub fn scrape(data: &str) -> Vec<String> { - let mut count = 0; let mut rfcs = vec![]; - let mut buff = String::from(""); - - for line in data.lines() { - // Skip first 65 lines - if count > 65 { - // Detect blank lines - if line == "" { - rfcs.push(buff); - buff = String::from(""); - } else { - buff = format!("{}{}", buff, line); - } - } else { - count += 1; - } + let mut iter = data.lines().skip(66).peekable(); + + while iter.peek().is_some() { + rfcs.push( + iter.by_ref() + .take_while(|s| !s.is_empty()) + .fold(String::new(), |acc, s| acc + s), + ); } rfcs } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn single_rfc_scrape() { + let data = String::from("\n".repeat(66)) + + "8989 Additional Criteria for Nominating Committee Eligibility. B.\n" + + " Carpenter, S. Farrell. February 2021. (Format: HTML, TXT, PDF, XML)\n" + + " (Status: EXPERIMENTAL) (DOI: 10.17487/RFC8989) \n"; + + let rfcs = vec![ + String::from("8989 Additional Criteria for Nominating Committee Eligibility. B.") + + " Carpenter, S. Farrell. February 2021. (Format: HTML, TXT, PDF, XML)" + + " (Status: EXPERIMENTAL) (DOI: 10.17487/RFC8989) ", + ]; + + assert_eq!(rfcs, scrape(&data)); + } + + #[test] + fn multi_rfc_scrape() { + let data = String::from("\n".repeat(66)) + + "8989 Additional Criteria for Nominating Committee Eligibility. B.\n" + + " Carpenter, S. Farrell. February 2021. (Format: HTML, TXT, PDF, XML)\n" + + " (Status: EXPERIMENTAL) (DOI: 10.17487/RFC8989) \n" + + "\n" + + "9003 Extended BGP Administrative Shutdown Communication. J. Snijders, J.\n" + + " Heitz, J. Scudder, A. Azimov. January 2021. (Format: HTML, TXT, PDF,\n" + + " XML) (Obsoletes RFC8203) (Updates RFC4486) (Status: PROPOSED\n" + + " STANDARD) (DOI: 10.17487/RFC9003) \n"; + + let rfcs = vec![ + String::from("8989 Additional Criteria for Nominating Committee Eligibility. B.") + + " Carpenter, S. Farrell. February 2021. (Format: HTML, TXT, PDF, XML)" + + " (Status: EXPERIMENTAL) (DOI: 10.17487/RFC8989) ", + String::from( + "9003 Extended BGP Administrative Shutdown Communication. J. Snijders, J.", + ) + " Heitz, J. Scudder, A. Azimov. January 2021. (Format: HTML, TXT, PDF," + + " XML) (Obsoletes RFC8203) (Updates RFC4486) (Status: PROPOSED" + + " STANDARD) (DOI: 10.17487/RFC9003) ", + ]; + + assert_eq!(rfcs, scrape(&data)); + } +}