class Classifoclc::Work

An abstract work. A work is not a physical book, but the conceptual work of which all the physical books are manifestions

Attributes

authors[R]

Public Class Methods

new(node) click to toggle source
# File lib/classifoclc/work.rb, line 6
def initialize(node)
  @node = node
  @work = node.css('work').first
  @authors = node.css('author').
               map{|a| Classifoclc::Author.new(a.text, a['lc'], a['viaf'])}
  @recommendations = load_recommendations(node)
end

Public Instance Methods

edition_count() click to toggle source

Get the number of editions the work has @return [Integer]

# File lib/classifoclc/work.rb, line 40
def edition_count
  @work['editions'].to_i
end
editions() click to toggle source

Get the editions of this work @return [Enumerator<Classifoclc::Edition>]

# File lib/classifoclc/work.rb, line 58
def editions
  Enumerator.new do |e|
    pages.each do |pg|
      pg.each do |edition|
        e << edition
      end
    end
  end
end
eholdings() click to toggle source

Get the number of libraries that hold a digital copy of this work @return [Integer]

# File lib/classifoclc/work.rb, line 52
def eholdings
  @work['eholdings'].to_i
end
format() click to toggle source

Get the format @return [String]

# File lib/classifoclc/work.rb, line 28
def format
  @work['format']
end
holdings() click to toggle source

Get the number of libraries that hold a copy of this work @return [Integer]

# File lib/classifoclc/work.rb, line 46
def holdings
  @work['holdings'].to_i
end
itemtype() click to toggle source

Get the type of item @return [String]

# File lib/classifoclc/work.rb, line 34
def itemtype
  @work['itemtype']
end
owi() click to toggle source

Get the work ID @return [String]

# File lib/classifoclc/work.rb, line 16
def owi
  @work['owi']
end
recommendations() click to toggle source

Get the recommended classifications for this work @return [Array<Classifoclc::Recommendations>]

# File lib/classifoclc/work.rb, line 70
def recommendations
  @recommendations
end
title() click to toggle source

Get the title @return [String]

# File lib/classifoclc/work.rb, line 22
def title
  @work['title']
end

Private Instance Methods

full(hsh = {}) click to toggle source
# File lib/classifoclc/work.rb, line 74
def full(hsh = {})
  params = {:identifier => 'owi', :value => owi,
            :summary => false}.merge(hsh)
  data = Classifoclc::fetch_data(params)
  editions = data.css('edition').map{|e| Edition::new(e)}

  navigation = data.css("navigation")

  next_page = nil
  unless navigation.empty?
    n = data.css("navigation next").first

    if n.nil?
      next_page = nil
    else
      next_page = n.text.to_i
    end
  end

  return {:editions => editions, :next => next_page}
end
load_recommendations(node) click to toggle source
# File lib/classifoclc/work.rb, line 109
def load_recommendations(node)
  recs = node.css('recommendations')
  return nil if recs.empty?

  return Recommendations.new(recs.first)
end
pages() click to toggle source

Iterate over pages of results

# File lib/classifoclc/work.rb, line 97
def pages
  hsh = full()
  Enumerator.new do |page|
    page << hsh[:editions]
    loop do
      break if hsh[:next].nil?
      hsh = full(:startRec => hsh[:next])
      page << hsh[:editions]
    end
  end
end