Switch to fixtures

This commit is contained in:
Nemo 2020-03-29 01:44:43 +05:30
parent df079ceaa0
commit f8debde5c5
8 changed files with 8133 additions and 86 deletions

View File

@ -1,88 +1,8 @@
require "./spec_helper"
describe Muse::Dl::Book do
it "it should parse the infobox" do
html = <<-EOT
<div class="column full">
<div class="title_wrap details">
<h2>Additional Information</h2>
</div>
<div class="details_tbl">
<div class="details_row">
<div class="cell label">
ISBN
</div>
<div class="cell">
9780813928517
</div>
</div>
<div class="details_row">
<div class="cell label">
Related ISBN
</div>
<div class="cell">
9780813928456
</div>
</div>
<div class="details_row">
<div class="cell label">
MARC Record
</div>
<div class="cell">
<a href="https://about.muse.jhu.edu/lib/metadata?filename=muse_book_875&amp;no_auth=1&amp;format=marc&amp;content_ids=book:875">Download</a>
</div>
</div>
<div class="details_row">
<div class="cell label">
OCLC
</div>
<div class="cell">
755633557
</div>
</div>
<div class="details_row">
<div class="cell label">
Pages
</div>
<div class="cell">
432
</div>
</div>
<div class="details_row">
<div class="cell label">
Launched on MUSE
</div>
<div class="cell">
2012-01-01
</div>
</div>
<div class="details_row">
<div class="cell label">
DOI
</div>
<div class="cell">
<a href="https://doi.org/10.1353/book.68534" target="_blank">10.1353/book.68534<img src="/images/link_blue.png" alt="external link" style="vertical-align:top;"></a>
</div>
</div>
<div class="details_row">
<div class="cell label">
Language
</div>
<div class="cell">
English
</div>
</div>
<div class="details_row">
<div class="cell label">
Open Access
</div>
<div class="cell">
No
</div>
</div>
</div>
</div>
EOT
it "it should parse the infobox for 875" do
html = File.new("spec/fixtures/book-875.html").gets_to_end
book = Muse::Dl::Book.new html
book.info["ISBN"].should eq "9780813928517"
book.info["Related ISBN"].should eq "9780813928456"
@ -91,6 +11,17 @@ EOT
book.info["Launched on MUSE"].should eq "2012-01-01"
book.info["Language"].should eq "English"
book.info["Open Access"].should eq "No"
end
it "it should parse the DOI for 68534" do
html = File.new("spec/fixtures/book-68534.html").gets_to_end
book = Muse::Dl::Book.new html
book.info["ISBN"].should eq "9781501737695"
book.info["Related ISBN"].should eq "9781501742583"
book.info["OCLC"].should eq "1122613406"
book.info["Launched on MUSE"].should eq "2019-10-10"
book.info["Language"].should eq "English"
book.info["Open Access"].should eq "Yes"
book.info["DOI"].should eq "10.1353/book.68534"
end
end

1995
spec/fixtures/book-68534.html vendored Normal file

File diff suppressed because it is too large Load Diff

2177
spec/fixtures/book-73090.html vendored Normal file

File diff suppressed because it is too large Load Diff

1995
spec/fixtures/book-8534.html vendored Normal file

File diff suppressed because it is too large Load Diff

1945
spec/fixtures/book-875.html vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,5 @@
require "./infoparser.cr"
require "myhtml"
module Muse::Dl
class Book
@ -6,7 +7,7 @@ module Muse::Dl
getter :info
def initialize(html : String)
@info = InfoParser.parse(html)
@info = InfoParser.infobox(Myhtml::Parser.new html)
end
end
end

View File

@ -2,9 +2,8 @@ require "myhtml"
module Muse::Dl
class InfoParser
def self.parse(html : String)
def self.infobox(myhtml : Myhtml::Parser)
info = Hash(String, String).new
myhtml = Myhtml::Parser.new(html)
myhtml.css(".details_row").each do |row|
label = row.css(".cell").map(&.inner_text).to_a[0].strip
value = row.css(".cell").map(&.inner_text).to_a[1].strip
@ -16,5 +15,8 @@ module Muse::Dl
end
return info
end
def self.title
end
end
end

View File

@ -1,4 +1,5 @@
require "./infoparser.cr"
require "myhtml"
module Muse::Dl
class Journal
@ -6,7 +7,7 @@ module Muse::Dl
getter :info
def initialize(html : String)
@info = InfoParser.parse(html)
@info = InfoParser.infobox(Myhtml::Parser.new html)
end
end
end