muse-dl/src/thing.cr

39 lines
1.1 KiB
Crystal
Raw Normal View History

require "./infoparser.cr"
require "myhtml"
module Muse::Dl
class Thing
@info = Hash(String, String).new
@title : String
@author : String
2020-04-03 19:40:11 +00:00
@date : String | Nil
@publisher : String
@summary : String
@summary_html : String
@cover_url : String
@thumbnail_url : String
2020-03-28 21:02:18 +00:00
@h : Myhtml::Parser
@formats : Set(Symbol)
getter :info, :title, :author, :date, :publisher, :summary, :summary_html, :cover_url, :thumbnail_url, :formats
2020-03-28 21:02:18 +00:00
private getter :h
def initialize(html : String)
2020-03-28 21:02:18 +00:00
@h = Myhtml::Parser.new html
@info = InfoParser.infobox(h)
id : String | Nil = InfoParser.id(h)
@title = InfoParser.title(h)
@author = InfoParser.author(h)
@date = InfoParser.date(h)
@publisher = InfoParser.publisher(h)
@summary = InfoParser.summary(h)
@summary_html = InfoParser.summary_html(h)
@formats = InfoParser.formats(h)
# TODO: Make this work for journals as well
@cover_url = "https://muse.jhu.edu/book/#{id}/image/front_cover.jpg"
@thumbnail_url = "https://muse.jhu.edu/book/#{id}/image/front_cover.jpg?format=180"
end
end
end