Class: EPUB::Publication::Package::Spine::Itemref

Inherits:
Object
  • Object
show all
Defined in:
lib/epub/publication/package/spine.rb

Constant Summary collapse

PAGE_SPREAD_PROPERTIES =
['left'.freeze, 'right'.freeze].freeze
PAGE_SPREAD_PREFIX =
'page-spread-'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeItemref

Returns a new instance of Itemref



50
51
52
# File 'lib/epub/publication/package/spine.rb', line 50

def initialize
  @properties = Set.new
end

Instance Attribute Details

#idObject

Returns the value of attribute id



46
47
48
# File 'lib/epub/publication/package/spine.rb', line 46

def id
  @id
end

#idrefObject

Returns the value of attribute idref



46
47
48
# File 'lib/epub/publication/package/spine.rb', line 46

def idref
  @idref
end

#linearObject

Returns the value of attribute linear



46
47
48
# File 'lib/epub/publication/package/spine.rb', line 46

def linear
  @linear
end

#propertiesObject

Returns the value of attribute properties



48
49
50
# File 'lib/epub/publication/package/spine.rb', line 48

def properties
  @properties
end

#spineObject

Returns the value of attribute spine



46
47
48
# File 'lib/epub/publication/package/spine.rb', line 46

def spine
  @spine
end

Instance Method Details

#==(other) ⇒ Object



73
74
75
76
77
78
79
# File 'lib/epub/publication/package/spine.rb', line 73

def ==(other)
  [:spine, :idref, :id].all? {|meth|
    self.__send__(meth) == other.__send__(meth)
  } and
    (linear? == other.linear?) and
    (properties == other.properties)
end

#itemPackage::Manifest::Item

Returns item referred by this object

Returns:



64
65
66
# File 'lib/epub/publication/package/spine.rb', line 64

def item
  @item ||= @spine.package.manifest[idref]
end

#item=(item) ⇒ Object



68
69
70
71
# File 'lib/epub/publication/package/spine.rb', line 68

def item=(item)
  self.idref = item.id
  item
end

#linear?true|false

Returns:

  • (true|false)


59
60
61
# File 'lib/epub/publication/package/spine.rb', line 59

def linear?
  !! linear
end

#page_spread"left", ...

Returns:

  • ("left", "right", nil)


82
83
84
85
# File 'lib/epub/publication/package/spine.rb', line 82

def page_spread
  property = properties.find {|prop| prop.start_with? PAGE_SPREAD_PREFIX}
  property ? property.gsub(/\A#{Regexp.escape(PAGE_SPREAD_PREFIX)}/, '') : nil
end

#page_spread=(new_value) ⇒ Object

Parameters:

  • new_value ("left", "right", nil)


88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/epub/publication/package/spine.rb', line 88

def page_spread=(new_value)
  if new_value.nil?
    properties.delete_if {|prop| prop.start_with? PAGE_SPREAD_PREFIX}
    return new_value
  end

  raise "Unsupported page-spread property: #{new_value}" unless PAGE_SPREAD_PROPERTIES.include? new_value

  props_to_be_deleted = (PAGE_SPREAD_PROPERTIES - [new_value]).map {|prop| "#{PAGE_SPREAD_PREFIX}#{prop}"}
  properties.delete_if {|prop| props_to_be_deleted.include? prop}
  new_property = "#{PAGE_SPREAD_PREFIX}#{new_value}"
  properties << new_property unless properties.include? new_property
  new_value
end