Class: EeePub::ContainerItem Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/eeepub/container_item.rb

Overview

This class is abstract.

Abstract base class for container item of ePub. Provides some helper methods.

Direct Known Subclasses

NCX, OCF::Container, OPF

Instance Method Summary collapse

Constructor Details

#initialize(values) ⇒ ContainerItem

Returns a new instance of ContainerItem.

Parameters:

  • values (Hash<Symbol, Object>)

    the hash of symbols and objects for attributes



35
36
37
# File 'lib/eeepub/container_item.rb', line 35

def initialize(values)
  set_values(values)
end

Instance Method Details

#save(filepath) ⇒ Object

Save as container item

Parameters:

  • filepath (String)

    the file path for container item



62
63
64
65
66
# File 'lib/eeepub/container_item.rb', line 62

def save(filepath)
  File.open(filepath, 'w') do |file|
    file << self.to_xml
  end
end

#set_values(values) ⇒ Object

Set values for attributes

Parameters:

  • values (Hash<Symbol, Object>)

    the hash of symbols and objects for attributes



42
43
44
45
46
# File 'lib/eeepub/container_item.rb', line 42

def set_values(values)
  values.each do |k, v|
    self.send(:"#{k}=", v)
  end
end

#to_xmlString

Convert to xml of container item

Returns:

  • (String)

    the xml of container item



51
52
53
54
55
56
57
# File 'lib/eeepub/container_item.rb', line 51

def to_xml
  out = ""
  builder = Builder::XmlMarkup.new(:target => out, :indent => 2)
  builder.instruct!
  build_xml(builder)
  out
end