Class: GEPUB::Bindings
Defined Under Namespace
Classes: MediaType
Constant Summary
Constants included
from XMLUtil
XMLUtil::DC_NS, XMLUtil::OPF_NS
Class Method Summary
collapse
Instance Method Summary
collapse
#inspect
Methods included from XMLUtil
#attr_to_hash, #ns_prefix, #raw_prefix
Constructor Details
#initialize {|_self| ... } ⇒ Bindings
Returns a new instance of Bindings.
19
20
21
22
23
|
# File 'lib/gepub/bindings.rb', line 19
def initialize
@media_types = []
@handler_by_media_type = {}
yield self if block_given?
end
|
Class Method Details
.parse(bindings_xml) ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/gepub/bindings.rb', line 25
def self.parse(bindings_xml)
Bindings.new {
|bindings|
bindings.instance_eval {
if !bindings_xml.nil?
@xml = bindings_xml
@namespaces = @xml.namespaces
@attributes = attr_to_hash(@xml.attributes)
@xml.xpath("//#{ns_prefix(OPF_NS)}:bindings/#{ns_prefix(OPF_NS)}:mediaType", @namespaces).map {
|mediaType|
@media_types << MediaType.new(mediaType['handler'], mediaType['media-type'])
@handler_by_media_type[mediaType['media-type']] = mediaType['handler']
}
end
}
}
end
|
Instance Method Details
#add(id, media_type) ⇒ Object
51
52
53
54
|
# File 'lib/gepub/bindings.rb', line 51
def add(id, media_type)
@media_types << MediaType.new(id, media_type)
@handler_by_media_type[media_type] = id
end
|
47
48
49
|
# File 'lib/gepub/bindings.rb', line 47
def handler_by_media_type
return @handler_by_media_type.dup
end
|
43
44
45
|
# File 'lib/gepub/bindings.rb', line 43
def media_types
return @media_types.dup
end
|
#to_xml(builder) ⇒ Object
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/gepub/bindings.rb', line 56
def to_xml(builder)
if (media_types.size > 0)
builder.bindings {
@media_types.each {
|mediaType|
mediaType.to_xml(builder)
}
}
end
end
|