Class: Epubber::Models::Book

Inherits:
Object
  • Object
show all
Includes:
Concerns::HasChapters, Concerns::HasCover, Concerns::HasEndnotes, Concerns::HasIntroduction
Defined in:
lib/epubber/models/book.rb

Instance Method Summary collapse

Methods included from Concerns::HasCover

#contextified_cover, #cover

Methods included from Concerns::HasEndnotes

#contextified_endnotes, #endnotes

Methods included from Concerns::HasIntroduction

#contextified_introduction, #introduction

Methods included from Concerns::HasChapters

#chapter, #chapters, #contextified_chapters

Constructor Details

#initializeBook

Returns a new instance of Book.



16
17
18
19
20
21
22
23
24
25
# File 'lib/epubber/models/book.rb', line 16

def initialize
  @title        = not_specified
  @author       = not_specified
  @publisher    = not_specified
  @language     = 'en'
  @url          = not_specified
  # LIST / OF / SUBJECTS => https://www.bisg.org/complete-bisac-subject-headings-2014-edition
  @subjects     = 'NON000000 NON-CLASSIFIABLE'
  @isbn         = nil
end

Instance Method Details

#author(text) ⇒ Object



32
33
34
# File 'lib/epubber/models/book.rb', line 32

def author(text)
  @author = text
end

#contextifyObject

Return a hash which can be used as a template’s context



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/epubber/models/book.rb', line 57

def contextify
  context = { 
    # Attributes
    "title" => @title, 
    "author" => @author,
    "publisher" => @publisher,
    "language" => @language,
    "url" => @url,
    "subjects" => @subjects,
    "uuid" => ::SecureRandom.uuid,
    "isbn" => @isbn
  }
  
  # Related models
  context["chapters"]     = contextified_chapters
  context["introduction"] = contextified_introduction
  context["endnotes"]     = contextified_endnotes
  context["cover"]        = contextified_cover

  context
end

#isbn(isbn) ⇒ Object



52
53
54
# File 'lib/epubber/models/book.rb', line 52

def isbn(isbn)
  @isbn = isbn
end

#language(lang) ⇒ Object



40
41
42
# File 'lib/epubber/models/book.rb', line 40

def language(lang)
  @language = lang
end

#publisher(text) ⇒ Object



36
37
38
# File 'lib/epubber/models/book.rb', line 36

def publisher(text)
  @publisher = text
end

#subjects(subjects) ⇒ Object



48
49
50
# File 'lib/epubber/models/book.rb', line 48

def subjects(subjects)
  @subjects = subjects
end

#title(text = nil) ⇒ Object



27
28
29
30
# File 'lib/epubber/models/book.rb', line 27

def title(text = nil)
  return @title if text.nil?
  @title = text
end

#url(url) ⇒ Object



44
45
46
# File 'lib/epubber/models/book.rb', line 44

def url(url)
  @url = url
end