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.



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

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



10
11
12
# File 'lib/gepub/spine.rb', line 10

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

Instance Method Details

#[](attribute) ⇒ Object

get attribute



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

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

#[]=(attribute, value) ⇒ Object

set attribute



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

def []=(attribute, value)
  @attributes[attribute] = value
end

#add_property(property) ⇒ Object



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

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

#page_spread_leftObject



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

def page_spread_left
  add_property 'page-spread-left'
end

#page_spread_rightObject



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

def page_spread_right
  add_property 'page-spread-right'
end

#rendition_layout=(val) ⇒ Object



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

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

#rendition_orientation=(val) ⇒ Object



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

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

#rendition_specified?Boolean

Returns:

  • (Boolean)


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

def rendition_specified?
  @rendition_specified
end

#rendition_spread=(val) ⇒ Object



70
71
72
# File 'lib/gepub/spine.rb', line 70

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

#set_rendition_param(name, val) ⇒ Object



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

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

#to_xml(builder, opf_version) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/gepub/spine.rb', line 74

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