class OpenStax::Content::BookPart

Attributes

book[R]
hash[R]
is_root[R]

Public Class Methods

new(hash: {}, is_root: false, book: nil) click to toggle source
# File lib/openstax/content/book_part.rb, line 5
def initialize(hash: {}, is_root: false, book: nil)
  @hash = hash
  @is_root = is_root
  @book = book
end

Public Instance Methods

book_location() click to toggle source
# File lib/openstax/content/book_part.rb, line 17
def book_location
  @book_location ||= parsed_title.book_location
end
contents() click to toggle source
# File lib/openstax/content/book_part.rb, line 34
def contents
  @contents ||= hash.fetch('contents')
end
parsed_title() click to toggle source
# File lib/openstax/content/book_part.rb, line 13
def parsed_title
  @parsed_title ||= OpenStax::Content::Title.new hash.fetch('title')
end
parts() click to toggle source
# File lib/openstax/content/book_part.rb, line 38
def parts
  @parts ||= contents.map do |hash|
    if hash.has_key? 'contents'
      self.class.new book: book, hash: hash
    else
      OpenStax::Content::Page.new book: book, hash: hash
    end
  end
end
title() click to toggle source
# File lib/openstax/content/book_part.rb, line 21
def title
  @title ||= parsed_title.text
end
uuid() click to toggle source

Old content used to have id == “subcol” for units and chapters If we encounter that, just assign a random UUID to them

# File lib/openstax/content/book_part.rb, line 27
def uuid
  @uuid ||= begin
    uuid = hash['id']
    uuid.nil? || uuid == 'subcol' ? SecureRandom.uuid : uuid.split('@').first
  end
end