class OpenStax::Content::Book

Attributes

archive_version[R]
uuid[R]
version[R]

Public Class Methods

new( archive_version:, uuid: nil, version: nil, hash: nil, title: nil, tree: nil, root_book_part: nil ) click to toggle source
# File lib/openstax/content/book.rb, line 5
def initialize(
  archive_version:, uuid: nil, version: nil, hash: nil, title: nil, tree: nil, root_book_part: nil
)
  @uuid            = uuid || (hash || {})['id']
  raise ArgumentError, 'Either uuid or hash with id key is required' if @uuid.nil?

  @version         = version || (hash || {})['version']
  raise ArgumentError, 'Either version or hash with version key is required' if @version.nil?

  @archive_version = archive_version
  @hash            = hash
  @title           = title
  @tree            = tree
  @root_book_part  = root_book_part
end

Public Instance Methods

archive() click to toggle source
# File lib/openstax/content/book.rb, line 23
def archive
  @archive ||= OpenStax::Content::Archive.new archive_version
end
baked() click to toggle source
# File lib/openstax/content/book.rb, line 35
def baked
  @baked ||= hash['baked']
end
collated() click to toggle source
# File lib/openstax/content/book.rb, line 39
def collated
  @collated ||= hash.fetch('collated', false)
end
hash() click to toggle source
# File lib/openstax/content/book.rb, line 43
def hash
  @hash ||= archive.json url
end
root_book_part() click to toggle source
# File lib/openstax/content/book.rb, line 67
def root_book_part
  @root_book_part ||= OpenStax::Content::BookPart.new(hash: tree, is_root: true, book: self)
end
short_id() click to toggle source
# File lib/openstax/content/book.rb, line 51
def short_id
  @short_id ||= hash['shortId']
end
title() click to toggle source
# File lib/openstax/content/book.rb, line 59
def title
  @title ||= hash.fetch('title')
end
tree() click to toggle source
# File lib/openstax/content/book.rb, line 63
def tree
  @tree ||= hash.fetch('tree')
end
url() click to toggle source
# File lib/openstax/content/book.rb, line 27
def url
  @url ||= archive.url_for "#{uuid}@#{version}"
end
url_fragment() click to toggle source
# File lib/openstax/content/book.rb, line 31
def url_fragment
  @url_fragment ||= url.chomp('.json')
end