R/scrape_rule_structure.R

Defines functions scrape_rule_structure

Documented in scrape_rule_structure

#' Scrape rule structure
#'
#' @param df Data frame with chapter URLs. Output of \code{"scrape_chapter_structure"}.
#' @param rulebook_date String. Date to scrape.
#'
#' @return Data frame with scraped rule structure.
#' @export
#'
#' @examples
#' \dontrun{
#' sectors <- scrape_sector_structure("http://www.prarulebook.co.uk/rulebook/Home/Handbook/16-11-2007")
#' parts <- scrape_part_structure(sectors)
#' chapters <- scrape_chapter_structure(parts)
#' rules <- scrape_rule_structure(chapters, "16-11-2007")
#' }
scrape_rule_structure <- function(df, rulebook_date) {
  cat("\n")
  cat("--- Scraping RULES ---")
  cat("\n")

  # TODO add input validation

  # new method - extract IDs - allows getting rule URLs
  # get all rules and append to a data frame
  rules <-
    purrr::map_df(df$chapter_url, scrape_menu,
                  selector = "a", rulebook_date = rulebook_date)

  rules_chapters_parts_sectors <-
    dplyr::left_join(rules, df,
                     by = "chapter_url")

  return(rules_chapters_parts_sectors)
}
mroliversmith/PRAClone documentation built on Jan. 11, 2020, 2:05 a.m.