Class: OpenStax::Content::Book

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/openstax/content/book.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(archive:, uuid:, version:, url: nil, hash: nil, slug: nil, style: nil) ⇒ Book

Returns a new instance of Book.



8
9
10
11
12
13
14
15
16
# File 'lib/openstax/content/book.rb', line 8

def initialize(archive:, uuid:, version:, url: nil, hash: nil, slug: nil, style: nil)
  @archive = archive
  @uuid = uuid
  @version = version
  @url = url
  @hash = hash
  @slug = slug
  @style = style
end

Instance Attribute Details

#archiveObject (readonly)

Returns the value of attribute archive.



6
7
8
# File 'lib/openstax/content/book.rb', line 6

def archive
  @archive
end

#slugObject (readonly)

Returns the value of attribute slug.



6
7
8
# File 'lib/openstax/content/book.rb', line 6

def slug
  @slug
end

#styleObject (readonly)

Returns the value of attribute style.



6
7
8
# File 'lib/openstax/content/book.rb', line 6

def style
  @style
end

#uuidObject (readonly)

Returns the value of attribute uuid.



6
7
8
# File 'lib/openstax/content/book.rb', line 6

def uuid
  @uuid
end

#versionObject (readonly)

Returns the value of attribute version.



6
7
8
# File 'lib/openstax/content/book.rb', line 6

def version
  @version
end

Instance Method Details

#bakedObject



30
31
32
# File 'lib/openstax/content/book.rb', line 30

def baked
  @baked ||= hash['baked']
end

#collatedObject



34
35
36
# File 'lib/openstax/content/book.rb', line 34

def collated
  @collated ||= hash.fetch('collated', false)
end

#hashObject



26
27
28
# File 'lib/openstax/content/book.rb', line 26

def hash
  @hash ||= archive.json url
end

#root_book_partObject



50
51
52
# File 'lib/openstax/content/book.rb', line 50

def root_book_part
  @root_book_part ||= OpenStax::Content::BookPart.new(hash: tree, is_root: true, book: self)
end

#short_idObject



38
39
40
# File 'lib/openstax/content/book.rb', line 38

def short_id
  @short_id ||= hash['shortId']
end

#titleObject



42
43
44
# File 'lib/openstax/content/book.rb', line 42

def title
  @title ||= hash.fetch('title')
end

#treeObject



46
47
48
# File 'lib/openstax/content/book.rb', line 46

def tree
  @tree ||= hash.fetch('tree')
end

#urlObject



18
19
20
# File 'lib/openstax/content/book.rb', line 18

def url
  @url ||= archive.url_for "#{uuid}@#{version}"
end

#url_fragmentObject



22
23
24
# File 'lib/openstax/content/book.rb', line 22

def url_fragment
  @url_fragment ||= url.chomp('.json')
end