Class: GEPUB::Spine::Itemref

Inherits:
Object
  • Object
show all
Defined in:
lib/gepub/spine.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(idref, parent = nil, attributes = {}) ⇒ Itemref

Returns a new instance of Itemref.



12
13
14
15
16
17
18
19
20
# File 'lib/gepub/spine.rb', line 12

def initialize(idref, parent = nil, attributes = {})
  if attributes['properties'].class == String
    attributes['properties'] = attributes['properties'].split(' ')
  end
  @attributes = {'idref' => idref}.merge(attributes)
  @parent = parent
  @parent.register_itemref(self) unless @parent.nil?
  self
end

Class Method Details

.create(parent, attributes = {}) ⇒ Object



8
9
10
# File 'lib/gepub/spine.rb', line 8

def self.create(parent, attributes = {})
  Itemref.new(attributes['idref'], parent, attributes.reject{|k,v| k == 'idref'})
end

Instance Method Details

#[](x) ⇒ Object



29
30
31
# File 'lib/gepub/spine.rb', line 29

def [](x)
  @attributes[x]
end

#[]=(x, y) ⇒ Object



33
34
35
# File 'lib/gepub/spine.rb', line 33

def []=(x,y)
  @attributes[x] = y
end

#add_property(property) ⇒ Object



37
38
39
# File 'lib/gepub/spine.rb', line 37

def add_property(property)
  (@attributes['properties'] ||=[]) << property
end

#page_spread_leftObject



45
46
47
# File 'lib/gepub/spine.rb', line 45

def page_spread_left
  add_property 'page-spread-left'
end

#page_spread_rightObject



41
42
43
# File 'lib/gepub/spine.rb', line 41

def page_spread_right
  add_property 'page-spread-right'
end

#to_xml(builder, opf_version) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/gepub/spine.rb', line 49

def to_xml(builder, opf_version)
  attr = @attributes.dup
  if opf_version.to_f < 3.0
    attr.reject!{ |k,v| k == 'properties' }
  end
  if !attr['properties'].nil?
    attr['properties'] = attr['properties'].join(' ')
    if attr['properties'].size == 0
      attr.delete 'properties'
    end
  end
  builder.itemref(attr)
end