Class: OpenStax::Cnx::V1::Book

Inherits:
Object
  • Object
show all
Defined in:
lib/openstax/cnx/v1/book.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id: nil, hash: nil, title: nil, tree: nil, root_book_part: nil) ⇒ Book

Returns a new instance of Book.



4
5
6
7
8
9
10
# File 'lib/openstax/cnx/v1/book.rb', line 4

def initialize(id: nil, hash: nil, title: nil, tree: nil, root_book_part: nil)
  @id             = id
  @hash           = hash
  @title          = title
  @tree           = tree
  @root_book_part = root_book_part
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



12
13
14
# File 'lib/openstax/cnx/v1/book.rb', line 12

def id
  @id
end

Instance Method Details

#bakedObject



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

def baked
  @baked ||= hash.fetch('baked', nil)
end

#canonical_urlObject



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

def canonical_url
  @canonical_url ||= OpenStax::Cnx::V1.archive_url_for("#{uuid}@#{version}")
end

#collatedObject



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

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

#hashObject



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

def hash
  @hash ||= OpenStax::Cnx::V1.fetch(url)
end

#root_book_partObject



54
55
56
# File 'lib/openstax/cnx/v1/book.rb', line 54

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

#short_idObject



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

def short_id
  @short_id ||= hash.fetch('shortId', nil)
end

#titleObject



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

def title
  @title ||= hash.fetch('title') { |key| raise "Book id=#{@id} is missing #{key}" }
end

#treeObject



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

def tree
  @tree ||= hash.fetch('tree') { |key| raise "Book id=#{@id} is missing #{key}" }
end

#urlObject



14
15
16
# File 'lib/openstax/cnx/v1/book.rb', line 14

def url
  @url ||= OpenStax::Cnx::V1.archive_url_for(id)
end

#uuidObject



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

def uuid
  @uuid ||= hash.fetch('id') { |key| raise "Book id=#{@id} is missing #{key}" }
end

#versionObject



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

def version
  @version ||= hash.fetch('version') { |key| raise "Book id=#{@id} is missing #{key}" }
end