Journal parser now parses all issues

This commit is contained in:
Nemo 2020-04-08 00:48:36 +05:30
parent d8702b2fcb
commit 4a358d0cb0
3 changed files with 28 additions and 3 deletions

View File

@ -20,4 +20,9 @@ describe Muse::Dl::Journal do
it "should parse publisher" do it "should parse publisher" do
j.publisher.should eq "Johns Hopkins University Press" j.publisher.should eq "Johns Hopkins University Press"
end end
it "should return issues" do
j.issues[0].id.should eq "41793"
j.issues[-1].id.should eq "1578"
end
end end

View File

@ -1,6 +1,13 @@
require "./thing.cr" require "./thing.cr"
module Muse::Dl module Muse::Dl
class Issue < Muse::Dl::Thing class Issue
@id : String
getter :id
def initialize(id : String)
@id = id
end
end end
end end

View File

@ -1,12 +1,13 @@
require "./infoparser.cr" require "./infoparser.cr"
require "myhtml" require "./issue.cr"
module Muse::Dl module Muse::Dl
class Journal class Journal
getter :info, :summary, :publisher getter :info, :summary, :publisher, :issues
@info = Hash(String, String).new @info = Hash(String, String).new
@summary : String @summary : String
@publisher : String @publisher : String
@issues = [] of Muse::Dl::Issue
private getter :h private getter :h
@ -15,6 +16,18 @@ module Muse::Dl
@info = InfoParser.infobox(h) @info = InfoParser.infobox(h)
@summary = InfoParser.summary(h) @summary = InfoParser.summary(h)
@publisher = InfoParser.journal_publisher(h) @publisher = InfoParser.journal_publisher(h)
parse_volumes(h)
end
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
@issues.push Muse::Dl::Issue.new matches[1]
end
end
end end
end end
end end