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


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

#rendition_layout=(val) ⇒ Object


58
59
60
# File 'lib/gepub/spine.rb', line 58

def rendition_layout=(val)
  set_rendition_param('layout', val)
end

#rendition_orientation=(val) ⇒ Object


62
63
64
# File 'lib/gepub/spine.rb', line 62

def rendition_orientation=(val)
  set_rendition_param('orientation', val)
end

#rendition_specified?Boolean


49
50
51
# File 'lib/gepub/spine.rb', line 49

def rendition_specified?
  @rendition_specified
end

#rendition_spread=(val) ⇒ Object


66
67
68
# File 'lib/gepub/spine.rb', line 66

def rendition_spread=(val)
  set_rendition_param('spread', val)
end

#set_rendition_param(name, val) ⇒ Object


53
54
55
56
# File 'lib/gepub/spine.rb', line 53

def set_rendition_param(name, val)
  add_property "rendition:#{name}-#{val}"
  @rendition_specified = true
end

#to_xml(builder, opf_version) ⇒ Object


70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/gepub/spine.rb', line 70

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