Class: GEPUB::Builder

Inherits:
Object
  • Object
show all
Includes:
BuilderMixin
Defined in:
lib/gepub/builder.rb

Defined Under Namespace

Classes: MetaItem

Instance Method Summary collapse

Methods included from BuilderMixin

#method_missing

Constructor Details

#initialize(attributes = {}, &block) ⇒ Builder

Returns a new instance of Builder.


182
183
184
185
186
187
188
# File 'lib/gepub/builder.rb', line 182

def initialize(attributes = {},  &block)
  @last_defined_item = nil
  @book = Book.new
  instance_eval(&block)
  # TODO check @book's consistency
  true
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class GEPUB::BuilderMixin

Instance Method Details

#alts(alt_vals = {}) ⇒ Object


251
252
253
254
255
256
257
# File 'lib/gepub/builder.rb', line 251

def alts(alt_vals = {})
  raise "can't specify alts on single item" if ! Array === @last_defined_item
  @last_defined_item.each_with_index {
    |item, index| 
    item.alt Hash[*(alt_vals.map{|k,v| [k,v[index]]}.flatten)]
  }
end

#collection(val, count = 1) ⇒ Object


211
212
213
214
# File 'lib/gepub/builder.rb', line 211

def collection(val, count = 1)
  @last_defined_item =
    MetaItem.new(@book.add_title(val, nil, GEPUB::TITLE_TYPE::COLLECTION).group_position(count.to_s))
end

#contributor(val, role = nil) ⇒ Object


259
260
261
# File 'lib/gepub/builder.rb', line 259

def contributor(val, role = nil)
  MetaItem.new(@book.add_contributor(val, nil, role))
end

#contributors(*vals) ⇒ Object


230
231
232
233
234
235
236
237
238
# File 'lib/gepub/builder.rb', line 230

def contributors(*vals)
  @last_defined_item = vals.map {
    |v|
    name = v
    role = nil
    name,role = v[0], v[1] if Array === name
    MetaItem.new(@book.add_contributor(name, nil, role))
  }
end

#creator(val, role = 'aut') ⇒ Object


216
217
218
# File 'lib/gepub/builder.rb', line 216

def creator(val, role = 'aut')
  MetaItem.new(@book.add_creator(val, nil, role))
end

#creators(*vals) ⇒ Object


220
221
222
223
224
225
226
227
228
# File 'lib/gepub/builder.rb', line 220

def creators(*vals)
  @last_defined_item = vals.map {
    |v|
    name = v
    role = 'aut'
    name,role = v[0], v[1] if Array === name
    MetaItem.new(@book.add_creator(name, nil, role))
  }
end

#generate_epub(path_to_epub) ⇒ Object


292
293
294
# File 'lib/gepub/builder.rb', line 292

def generate_epub(path_to_epub)
  @book.generate_epub(path_to_epub)
end

#generate_epub_streamObject


300
301
302
# File 'lib/gepub/builder.rb', line 300

def generate_epub_stream
  @book.generate_epub_stream
end

#ibooks_scroll_axis(val) ⇒ Object

specify scroll axis for ibooks


273
274
275
# File 'lib/gepub/builder.rb', line 273

def ibooks_scroll_axis(val)
  @book.ibooks_scroll_axis = val
end

#ibooks_version(val) ⇒ Object

specify version for ibooks


269
270
271
# File 'lib/gepub/builder.rb', line 269

def ibooks_version(val)
  @book.ibooks_version=val
end

#optional_file(val) ⇒ Object

set optional file. val should be String or Hash. if val is String, file is read from the File specified by string and stored in EPUB to the path specified by string. if val is Hash, file is read from the value and stored in EPUB to the path specified by the key.


281
282
283
284
285
286
287
288
289
290
# File 'lib/gepub/builder.rb', line 281

def optional_file(val)
  path = val
  io = val if String === val
  if Hash === val
    raise 'argument to optional_file should be length 1' if val.size != 1
    path = val.first[0]
    io = val.first[1]
  end
  @book.add_optional_file(path, io)
end

#page_progression_direction(val) ⇒ Object

set page progression direction.


264
265
266
267
# File 'lib/gepub/builder.rb', line 264

def page_progression_direction(val)
  raise assert unless ['rtl', 'ltr', 'default'].member? val
  @book.page_progression_direction = val
end

#publishers(*vals) ⇒ Object


240
241
242
243
244
245
# File 'lib/gepub/builder.rb', line 240

def publishers(*vals)
  @last_defined_item = vals.map {
    |v|
    MetaItem.new(@book.add_publisher(v, nil))
  }
end

#resources(attributes = {}, &block) ⇒ Object


296
297
298
# File 'lib/gepub/builder.rb', line 296

def resources(attributes = {}, &block)
  ResourceBuilder.new(@book, attributes, &block)
end

#unique_identifier(val, id = 'BookID', scheme = 'nil') ⇒ Object


247
248
249
# File 'lib/gepub/builder.rb', line 247

def unique_identifier(val, id = 'BookID', scheme = 'nil')
  @last_defined_item = MetaItem.new(@book.primary_identifier(val, id, scheme))
end