Class: Epuber::Book::TocItem
Instance Attribute Summary collapse
#parent, #sub_items
Attributes inherited from DSL::Object
#file_path
Instance Method Summary
collapse
#create_child_item, #create_child_items, #flat_sub_items, #freeze, #initialize, #root?, #validate
Methods inherited from DSL::Object
#freeze, from_file, #from_file?, from_string, #initialize, #to_s, #validate
#attribute, #define_method_attr, #dsl_attributes, #find_root
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Epuber::DSL::Object
Instance Attribute Details
#file_fragment ⇒ String
27
28
29
|
# File 'lib/epuber/book/toc_item.rb', line 27
def file_fragment
@file_fragment
end
|
Instance Method Details
#file(file_path, title = nil, *opts) ⇒ Object
Creating sub item from file
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
# File 'lib/epuber/book/toc_item.rb', line 84
def file(file_path, title = nil, *opts)
create_child_item do |item|
unless file_path.nil?
file_pattern, file_fragment = file_path.split('#')
unless file_pattern.nil? || file_pattern.empty?
file_obj = FileRequest.new(file_pattern, group: :text)
item.file_request = file_obj
end
item.file_fragment = file_fragment unless file_fragment.nil? || file_fragment.empty?
end
if title.is_a?(String)
item.title = title
else
opts.unshift(title)
end
item.options = opts.map do |i|
if i.is_a?(Hash)
i.map do |j_key, j_value|
{ j_key => j_value }
end
else
i
end
end.flatten
yield item if block_given?
end
end
|
12
13
14
|
# File 'lib/epuber/book/toc_item.rb', line 12
attribute :file_request,
auto_convert: { String => FileRequest },
inherited: true
|
#full_source_pattern ⇒ String
56
57
58
|
# File 'lib/epuber/book/toc_item.rb', line 56
def full_source_pattern
[file_request.source_pattern, file_fragment].compact.join('#')
end
|
#item(title, *opts) ⇒ Object
Creating sub item without reference to file
121
122
123
|
# File 'lib/epuber/book/toc_item.rb', line 121
def item(title, *opts)
file(nil, title, *opts)
end
|
#landmarks ⇒ Array<Symbol>
34
35
36
37
38
|
# File 'lib/epuber/book/toc_item.rb', line 34
def landmarks
options.select do |item|
item.is_a?(Symbol) && item.to_s.start_with?('landmark')
end
end
|
#linear? ⇒ Bool
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/epuber/book/toc_item.rb', line 42
def linear?
first = options.select do |item|
item.is_a?(Hash) && (item.include?(:linear) || item.include?('linear'))
end.first
if first.nil?
true
else
first.values.first
end
end
|
#local_source_pattern ⇒ String
62
63
64
65
66
67
68
|
# File 'lib/epuber/book/toc_item.rb', line 62
def local_source_pattern
file_request = attributes_values[:file_request]
return "##{file_fragment}" if file_request.nil?
[file_request.source_pattern, file_fragment].compact.join('#')
end
|
#options ⇒ Array<Symbol | Hash<Symbol, Object>>
22
23
|
# File 'lib/epuber/book/toc_item.rb', line 22
attribute :options,
default_value: []
|
#title ⇒ String
18
|
# File 'lib/epuber/book/toc_item.rb', line 18
attribute :title
|