muse-dl/src/book.cr

27 lines
551 B
Crystal
Raw Permalink Normal View History

require "./thing.cr"
2020-03-28 20:02:55 +00:00
module Muse::Dl
class Book < Muse::Dl::Thing
2020-03-28 21:02:18 +00:00
@chapters : Array(Array(String))
getter :chapters
def initialize(html : String)
super(html)
@chapters = parts(@h)
end
def parts(myhtml : Myhtml::Parser)
chapters = [] of Array(String)
myhtml.css(".title a").each do |a|
link = a.attribute_by("href").to_s
matches = /\/chapter\/(\d+)/.match link
if matches
chapters.push [matches[1], a.inner_text]
end
end
chapters
end
2020-03-28 20:02:55 +00:00
end
end