Class: Peregrin::Book

Inherits:
Object
  • Object
show all
Defined in:
lib/peregrin/book.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBook

Returns a new instance of Book.



32
33
34
35
36
37
38
39
# File 'lib/peregrin/book.rb', line 32

def initialize
  @components = []
  @chapters = []
  @properties = []
  @format_properties = []
  @resources = []
  @blueprints = []
end

Instance Attribute Details

#blueprintsObject

An array of Blueprints (ie, metadata files like the OPF or NCX).



23
24
25
# File 'lib/peregrin/book.rb', line 23

def blueprints
  @blueprints
end

#chaptersObject

A tree of Chapters. Top-level chapters in this array, each with children arrays.



11
12
13
# File 'lib/peregrin/book.rb', line 11

def chapters
  @chapters
end

#componentsObject

An array of Components



7
8
9
# File 'lib/peregrin/book.rb', line 7

def components
  @components
end

#coverObject

A Resource that is used for the book cover.



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

def cover
  @cover
end

#format_propertiesObject

An array of Properties relating to the format of the ebook.



17
18
19
# File 'lib/peregrin/book.rb', line 17

def format_properties
  @format_properties
end

#identifierObject

Unique identifier for this book



4
5
6
# File 'lib/peregrin/book.rb', line 4

def identifier
  @identifier
end

#propertiesObject

An array of Properties containg the ebook-supplied metadata.



14
15
16
# File 'lib/peregrin/book.rb', line 14

def properties
  @properties
end

#read_resource_proc=(value) ⇒ Object (writeonly)

A proc that copies a resource to the given destination.



29
30
31
# File 'lib/peregrin/book.rb', line 29

def read_resource_proc=(value)
  @read_resource_proc = value
end

#resourcesObject

An array of Resources.



20
21
22
# File 'lib/peregrin/book.rb', line 20

def resources
  @resources
end

Instance Method Details

#add_blueprint(*args) ⇒ Object



57
58
59
# File 'lib/peregrin/book.rb', line 57

def add_blueprint(*args)
  @blueprints.push(Peregrin::Blueprint.new(*args)).last
end

#add_chapter(*args) ⇒ Object



67
68
69
# File 'lib/peregrin/book.rb', line 67

def add_chapter(*args)
  @chapters.push(Peregrin::Chapter.new(*args)).last
end

#add_component(*args) ⇒ Object



47
48
49
# File 'lib/peregrin/book.rb', line 47

def add_component(*args)
  @components.push(Peregrin::Component.new(*args)).last
end

#add_format_property(*args) ⇒ Object



84
85
86
# File 'lib/peregrin/book.rb', line 84

def add_format_property(*args)
  @format_properties.push(Peregrin::Property.new(*args)).last
end

#add_property(*args) ⇒ Object



72
73
74
# File 'lib/peregrin/book.rb', line 72

def add_property(*args)
  @properties.push(Peregrin::Property.new(*args)).last
end

#add_resource(*args) ⇒ Object



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

def add_resource(*args)
  @resources.push(Peregrin::Resource.new(*args)).last
end

#all_filesObject



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

def all_files
  @components + @resources + @blueprints
end

#blueprint_for(rel) ⇒ Object



62
63
64
# File 'lib/peregrin/book.rb', line 62

def blueprint_for(rel)
  @blueprints.detect { |bp| bp.rel == rel }
end

#copy_resource_to(resource_path, dest_path) ⇒ Object



119
120
121
122
123
# File 'lib/peregrin/book.rb', line 119

def copy_resource_to(resource_path, dest_path)
  File.open(dest_path, 'w') { |f|
    f << read_resource(resource_path)
  }
end

#deep_cloneObject



126
127
128
129
130
131
132
133
# File 'lib/peregrin/book.rb', line 126

def deep_clone
  @read_resource_proc ||= nil
  tmp = @read_resource_proc
  @read_resource_proc = nil
  clone = Marshal.load(Marshal.dump(self))
  clone.read_resource_proc = @read_resource_proc = tmp
  clone
end

#directionObject

The page progression direction. Can be “ltr” (left to right), “rtl” (right to left) or nil (omitted). Only used for EPUB for now.



109
110
111
# File 'lib/peregrin/book.rb', line 109

def direction
  format_property_for('page-progression-direction')
end

#format_property_for(key) ⇒ Object



89
90
91
92
93
# File 'lib/peregrin/book.rb', line 89

def format_property_for(key)
  key = key.to_s
  prop = @format_properties.detect { |p| p.key == key }
  prop ? prop.value : nil
end

#property_for(key) ⇒ Object



77
78
79
80
81
# File 'lib/peregrin/book.rb', line 77

def property_for(key)
  key = key.to_s
  prop = @properties.detect { |p| p.key == key }
  prop ? prop.value : nil
end

#read_resource(resource_path) ⇒ Object



114
115
116
# File 'lib/peregrin/book.rb', line 114

def read_resource(resource_path)
  @read_resource_proc.call(resource_path)  if @read_resource_proc
end

#versionObject

The current version of document specifications. Only used for EPUB for now.



99
100
101
102
# File 'lib/peregrin/book.rb', line 99

def version
  v = format_property_for('version')
  v ? v.to_f : nil
end