muse-dl/src/journal.cr

45 lines
1.0 KiB
Crystal
Raw Normal View History

require "./infoparser.cr"
2020-04-07 19:18:36 +00:00
require "./issue.cr"
2020-03-28 20:02:55 +00:00
module Muse::Dl
class Journal
getter :info, :summary, :publisher, :issues, :title
@info = Hash(String, String).new
@summary : String
@publisher : String
2020-04-07 19:18:36 +00:00
@issues = [] of Muse::Dl::Issue
@title : String
private getter :h
def initialize(html)
@h = Myhtml::Parser.new html
@info = InfoParser.infobox(h)
@summary = InfoParser.summary(h)
@publisher = InfoParser.journal_publisher(h)
@title = InfoParser.journal_title(h)
2020-04-07 19:18:36 +00:00
parse_volumes(h)
end
2020-06-30 12:29:56 +00:00
def open_access
if @info.has_key? "Open Access"
return @info["Open Access"] == "Yes"
end
false
end
2020-04-07 19:18:36 +00:00
def parse_volumes(myhtml : Myhtml::Parser)
myhtml.css("#available_issues_list_text a").each do |a|
link = a.attribute_by("href").to_s
matches = /\/issue\/(\d+)/.match link
if matches
issue = Muse::Dl::Issue.new matches[1]
issue.journal_title = @title
@issues.push issue
2020-04-07 19:18:36 +00:00
end
end
end
2020-03-28 20:02:55 +00:00
end
end