Class: Peregrin::Book
- Inherits:
-
Object
- Object
- Peregrin::Book
- Defined in:
- lib/peregrin/book.rb
Instance Attribute Summary (collapse)
-
- (Object) chapters
A tree of Chapters.
-
- (Object) components
An array of Components.
-
- (Object) cover
A Resource that is used for the book cover.
-
- (Object) identifier
Unique identifier for this book.
-
- (Object) properties
An array of Properties.
-
- (Object) read_resource_proc
writeonly
A proc that copies a resource to the given destination.
-
- (Object) resources
An array of Resources.
Instance Method Summary (collapse)
- - (Object) add_chapter(*args)
- - (Object) add_component(*args)
- - (Object) add_property(*args)
- - (Object) add_resource(*args)
- - (Object) all_files
- - (Object) copy_resource_to(resource_path, dest_path)
- - (Object) deep_clone
-
- (Book) initialize
constructor
A new instance of Book.
- - (Object) property_for(key)
- - (Object) read_resource(resource_path)
Constructor Details
- (Book) initialize
A new instance of Book
26 27 28 29 30 31 |
# File 'lib/peregrin/book.rb', line 26 def initialize @components = [] @chapters = [] @properties = [] @resources = [] end |
Instance Attribute Details
- (Object) chapters
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 |
- (Object) components
An array of Components
7 8 9 |
# File 'lib/peregrin/book.rb', line 7 def components @components end |
- (Object) cover
A Resource that is used for the book cover.
20 21 22 |
# File 'lib/peregrin/book.rb', line 20 def cover @cover end |
- (Object) identifier
Unique identifier for this book
4 5 6 |
# File 'lib/peregrin/book.rb', line 4 def identifier @identifier end |
- (Object) properties
An array of Properties.
14 15 16 |
# File 'lib/peregrin/book.rb', line 14 def properties @properties end |
- (Object) read_resource_proc=(value) (writeonly)
A proc that copies a resource to the given destination.
23 24 25 |
# File 'lib/peregrin/book.rb', line 23 def read_resource_proc=(value) @read_resource_proc = value end |
- (Object) resources
An array of Resources.
17 18 19 |
# File 'lib/peregrin/book.rb', line 17 def resources @resources end |
Instance Method Details
- (Object) add_chapter(*args)
49 50 51 |
# File 'lib/peregrin/book.rb', line 49 def add_chapter(*args) @chapters.push(Peregrin::Chapter.new(*args)).last end |
- (Object) add_component(*args)
39 40 41 |
# File 'lib/peregrin/book.rb', line 39 def add_component(*args) @components.push(Peregrin::Component.new(*args)).last end |
- (Object) add_property(*args)
54 55 56 |
# File 'lib/peregrin/book.rb', line 54 def add_property(*args) @properties.push(Peregrin::Property.new(*args)).last end |
- (Object) add_resource(*args)
44 45 46 |
# File 'lib/peregrin/book.rb', line 44 def add_resource(*args) @resources.push(Peregrin::Resource.new(*args)).last end |
- (Object) all_files
34 35 36 |
# File 'lib/peregrin/book.rb', line 34 def all_files @components + @resources end |
- (Object) copy_resource_to(resource_path, dest_path)
71 72 73 74 75 |
# File 'lib/peregrin/book.rb', line 71 def copy_resource_to(resource_path, dest_path) File.open(dest_path, 'w') { |f| f << read_resource(resource_path) } end |
- (Object) deep_clone
78 79 80 81 82 83 84 85 |
# File 'lib/peregrin/book.rb', line 78 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 |
- (Object) property_for(key)
59 60 61 62 63 |
# File 'lib/peregrin/book.rb', line 59 def property_for(key) key = key.to_s prop = @properties.detect { |p| p.key == key } prop ? prop.value : nil end |
- (Object) read_resource(resource_path)
66 67 68 |
# File 'lib/peregrin/book.rb', line 66 def read_resource(resource_path) @read_resource_proc.call(resource_path) if @read_resource_proc end |