Class: GEPUB::Spine
Defined Under Namespace
Classes: Itemref
Constant Summary
Constants included
from XMLUtil
XMLUtil::DC_NS, XMLUtil::OPF_NS
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#inspect
Methods included from XMLUtil
#attr_to_hash, #ns_prefix, #raw_prefix
Constructor Details
#initialize(opf_version = '3.0', id_pool = Package::IDPool.new) {|_self| ... } ⇒ Spine
Returns a new instance of Spine.
106
107
108
109
110
111
112
113
|
# File 'lib/gepub/spine.rb', line 106
def initialize(opf_version = '3.0', id_pool = Package::IDPool.new)
@id_pool = id_pool
@attributes = {}
@item_refs = []
@itemref_by_id = {}
@opf_version = opf_version
yield self if block_given?
end
|
Instance Attribute Details
#opf_version ⇒ Object
Returns the value of attribute opf_version.
8
9
10
|
# File 'lib/gepub/spine.rb', line 8
def opf_version
@opf_version
end
|
Class Method Details
.parse(spine_xml, opf_version = '3.0', id_pool = Package::IDPool.new) ⇒ Object
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
# File 'lib/gepub/spine.rb', line 89
def self.parse(spine_xml, opf_version = '3.0', id_pool = Package::IDPool.new)
Spine.new(opf_version, id_pool) {
|spine|
spine.instance_eval {
@xml = spine_xml
@namespaces = @xml.namespaces
@attributes = attr_to_hash(@xml.attributes)
@item_refs = []
@xml.xpath("//#{ns_prefix(OPF_NS)}:spine/#{ns_prefix(OPF_NS)}:itemref", @namespaces).map {
|itemref|
i = Itemref.create(self, attr_to_hash(itemref.attributes))
@item_refs << i
}
}
}
end
|
Instance Method Details
#<<(item) ⇒ Object
136
137
138
|
# File 'lib/gepub/spine.rb', line 136
def <<(item)
push item
end
|
#itemref_by_id ⇒ Object
126
127
128
|
# File 'lib/gepub/spine.rb', line 126
def itemref_by_id
@itemref_by_id.dup
end
|
#itemref_list ⇒ Object
122
123
124
|
# File 'lib/gepub/spine.rb', line 122
def itemref_list
@item_refs.dup
end
|
#push(item) ⇒ Object
130
131
132
133
134
|
# File 'lib/gepub/spine.rb', line 130
def push(item)
@item_refs << i = Itemref.new(item.id, self)
@itemref_by_id[item.id] = i
i
end
|
#register_itemref(itemref) ⇒ Object
153
154
155
156
|
# File 'lib/gepub/spine.rb', line 153
def register_itemref(itemref)
raise "id '#{itemref.id}' is already in use." if @id_pool[itemref.id]
@id_pool[itemref.id] = true unless itemref.id.nil?
end
|
#remove_with_idlist(ids) ⇒ Object
163
164
165
166
167
168
|
# File 'lib/gepub/spine.rb', line 163
def remove_with_idlist(ids)
@item_refs = @item_refs.select {
|ref|
!ids.member? ref.idref
}
end
|
#rendition_specified? ⇒ Boolean
140
141
142
|
# File 'lib/gepub/spine.rb', line 140
def rendition_specified?
@item_refs.select { |itemref| itemref.rendition_specified? }.size > 0
end
|
#to_xml(builder) ⇒ Object
144
145
146
147
148
149
150
151
|
# File 'lib/gepub/spine.rb', line 144
def to_xml(builder)
builder.spine(@attributes) {
@item_refs.each {
|ref|
ref.to_xml(builder, @opf_version)
}
}
end
|
#unregister_itemref(itemref) ⇒ Object
158
159
160
161
|
# File 'lib/gepub/spine.rb', line 158
def unregister_itemref(itemref)
@item_refs.delete itemref
@id_pool[itemref.id] = nil
end
|