Class: OpenStax::Cnx::V1::Book
- Inherits:
-
Object
- Object
- OpenStax::Cnx::V1::Book
- Defined in:
- lib/openstax/cnx/v1/book.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
- #baked ⇒ Object
- #canonical_url ⇒ Object
- #collated ⇒ Object
- #hash ⇒ Object
-
#initialize(id: nil, hash: nil, title: nil, tree: nil, root_book_part: nil) ⇒ Book
constructor
A new instance of Book.
- #root_book_part ⇒ Object
- #short_id ⇒ Object
- #title ⇒ Object
- #tree ⇒ Object
- #url ⇒ Object
- #uuid ⇒ Object
- #version ⇒ Object
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
#id ⇒ Object (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
#baked ⇒ Object
18 19 20 |
# File 'lib/openstax/cnx/v1/book.rb', line 18 def baked @baked ||= hash.fetch('baked', nil) end |
#canonical_url ⇒ Object
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 |
#collated ⇒ Object
22 23 24 |
# File 'lib/openstax/cnx/v1/book.rb', line 22 def collated @collated ||= hash.fetch('collated', nil) end |
#hash ⇒ Object
26 27 28 |
# File 'lib/openstax/cnx/v1/book.rb', line 26 def hash @hash ||= OpenStax::Cnx::V1.fetch(url) end |
#root_book_part ⇒ Object
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_id ⇒ Object
34 35 36 |
# File 'lib/openstax/cnx/v1/book.rb', line 34 def short_id @short_id ||= hash.fetch('shortId', nil) end |
#title ⇒ Object
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 |
#tree ⇒ Object
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 |
#url ⇒ Object
14 15 16 |
# File 'lib/openstax/cnx/v1/book.rb', line 14 def url @url ||= OpenStax::Cnx::V1.archive_url_for(id) end |
#uuid ⇒ Object
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 |
#version ⇒ Object
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 |