class GEPUB::Spine::Itemref

Public Class Methods

create(parent, attributes = {}) click to toggle source
# File lib/gepub/spine.rb, line 8
def self.create(parent, attributes = {})
  Itemref.new(attributes['idref'], parent, attributes.reject{|k,_v| k == 'idref'})
end
new(idref, parent = nil, attributes = {}) click to toggle source
# 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

Public Instance Methods

[](x) click to toggle source
# File lib/gepub/spine.rb, line 29
def [](x)
  @attributes[x]
end
[]=(x,y) click to toggle source
# File lib/gepub/spine.rb, line 33
def []=(x,y)
  @attributes[x] = y
end
add_property(property) click to toggle source
# File lib/gepub/spine.rb, line 37
def add_property(property)
  (@attributes['properties'] ||=[]) << property
end
page_spread_left() click to toggle source
# File lib/gepub/spine.rb, line 45
def page_spread_left
  add_property 'page-spread-left'
end
page_spread_right() click to toggle source
# File lib/gepub/spine.rb, line 41
def page_spread_right
  add_property 'page-spread-right'
end
rendition_layout=(val) click to toggle source
# File lib/gepub/spine.rb, line 58
def rendition_layout=(val)
  set_rendition_param('layout', val)
end
rendition_orientation=(val) click to toggle source
# File lib/gepub/spine.rb, line 62
def rendition_orientation=(val)
  set_rendition_param('orientation', val)
end
rendition_specified?() click to toggle source
# File lib/gepub/spine.rb, line 49
def rendition_specified?
  @rendition_specified
end
rendition_spread=(val) click to toggle source
# File lib/gepub/spine.rb, line 66
def rendition_spread=(val)
  set_rendition_param('spread', val)
end
set_rendition_param(name, val) click to toggle source
# 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) click to toggle source
# 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