///|
pub fn explain(text : String, agent : String, paths : Array[String]) -> String {
let robots = parse(text)
let lines : Array[String] = []
lines.push(summary(robots))
for path in paths {
lines.push(decision_line(decide(robots, agent, path)))
}
join_lines(lines)
}
///|
pub fn summary(robots : Robots) -> String {
"robots groups=" +
robots.groups.length().to_string() +
" sitemaps=" +
robots.sitemaps.length().to_string() +
" hosts=" +
robots.hosts.length().to_string()
}
///|
pub fn group_summary(group : Group) -> String {
"agents=" +
join_with(group.agents, ",") +
" rules=" +
group.rules.length().to_string() +
" crawl_delay=" +
delay_text(group.crawl_delay)
}
///|
pub fn delay_text(delay : Int?) -> String {
match delay {
Some(value) => value.to_string()
None => "none"
}
}
///|
pub fn robots_digest(text : String) -> Array[String] {
let robots = parse(text)
let lines : Array[String] = []
lines.push(summary(robots))
for group in robots.groups {
lines.push(group_summary(group))
}
for sitemap in robots.sitemaps {
lines.push("sitemap=" + sitemap)
}
for host in robots.hosts {
lines.push("host=" + host)
}
lines
}