Class: OpenStax::Content::Book
- Inherits:
-
Object
- Object
- OpenStax::Content::Book
- Defined in:
- lib/openstax/content/book.rb
Instance Attribute Summary collapse
-
#archive_version ⇒ Object
readonly
Returns the value of attribute archive_version.
-
#uuid ⇒ Object
readonly
Returns the value of attribute uuid.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #archive ⇒ Object
- #baked ⇒ Object
- #collated ⇒ Object
- #hash ⇒ Object
-
#initialize(archive_version:, uuid: nil, version: 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
- #url_fragment ⇒ Object
Constructor Details
#initialize(archive_version:, uuid: nil, version: nil, hash: nil, title: nil, tree: nil, root_book_part: nil) ⇒ Book
Returns a new instance of Book.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# 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 |
Instance Attribute Details
#archive_version ⇒ Object (readonly)
Returns the value of attribute archive_version.
21 22 23 |
# File 'lib/openstax/content/book.rb', line 21 def archive_version @archive_version end |
#uuid ⇒ Object (readonly)
Returns the value of attribute uuid.
21 22 23 |
# File 'lib/openstax/content/book.rb', line 21 def uuid @uuid end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
21 22 23 |
# File 'lib/openstax/content/book.rb', line 21 def version @version end |
Instance Method Details
#archive ⇒ Object
23 24 25 |
# File 'lib/openstax/content/book.rb', line 23 def archive @archive ||= OpenStax::Content::Archive.new archive_version end |
#baked ⇒ Object
35 36 37 |
# File 'lib/openstax/content/book.rb', line 35 def baked @baked ||= hash['baked'] end |
#collated ⇒ Object
39 40 41 |
# File 'lib/openstax/content/book.rb', line 39 def collated @collated ||= hash.fetch('collated', false) end |
#hash ⇒ Object
43 44 45 |
# File 'lib/openstax/content/book.rb', line 43 def hash @hash ||= archive.json url end |
#root_book_part ⇒ Object
67 68 69 |
# 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 ⇒ Object
51 52 53 |
# File 'lib/openstax/content/book.rb', line 51 def short_id @short_id ||= hash['shortId'] end |
#title ⇒ Object
59 60 61 |
# File 'lib/openstax/content/book.rb', line 59 def title @title ||= hash.fetch('title') end |
#tree ⇒ Object
63 64 65 |
# File 'lib/openstax/content/book.rb', line 63 def tree @tree ||= hash.fetch('tree') end |
#url ⇒ Object
27 28 29 |
# File 'lib/openstax/content/book.rb', line 27 def url @url ||= archive.url_for "#{uuid}@#{version}" end |
#url_fragment ⇒ Object
31 32 33 |
# File 'lib/openstax/content/book.rb', line 31 def url_fragment @url_fragment ||= url.chomp('.json') end |