relaton / relaton-iso

RelatonIso: ISO Standards metadata using the BibliographicItem model
BSD 2-Clause "Simplified" License
2 stars 1 forks source link

Scrapper should return `HitPage`s and `HitCollection`s instead of itself #13

Closed ronaldtse closed 6 years ago

ronaldtse commented 6 years ago

Implement a class HitCollection < Array (which already includes Enumerable) so that we not only have the each method but also the rest, like length?

An array of HitPages should be the result returned by Scrapper.

This allows something like:

s = Isobib::IsoBibliography.search '19115' # => #<Isobib::HitPages ...>
page1 = s.first  # => #<Isobib::HitCollection ... >
page1.first # => #<Isobib::Hit ...>

Accessing the second page of search results:

page2 = s[1]  # => #<Isobib::HitCollection @fetched=false... >
page2.fetch  # => #<Isobib::HitCollection @fetched=true >
page2.first # => #<Isobib::Hit ...>
ronaldtse commented 6 years ago

Related to https://github.com/riboseinc/isobib/issues/12

andrew2net commented 6 years ago

@ronaldtse do we really need HitPages? It's possible to implement Array's methods for HitCollection. We can lazy load pages automatically when an index is out of a current page. So we don't have to manipulate pages by hand.

ronaldtse commented 6 years ago

@andrew2net yes it's possible to use HitCollection indeed -- my concern was what is the best way to communicate to users when lazy load will happen, and also how to make it not happen (as you imagine it is important to server-side code).

We can have a LazyCollection that automatically calls hit.fetch on access too. Thoughts?

ronaldtse commented 6 years ago

P.S. I agree with you that HitPages is not something the user needs to access, it might be useful internally, though.

andrew2net commented 6 years ago

implemented HitCollection and HitPage