Class: EPUB::Publication::Package::Spine::Itemref
- Inherits:
-
Object
- Object
- EPUB::Publication::Package::Spine::Itemref
- 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
-
#id ⇒ Object
Returns the value of attribute id.
-
#idref ⇒ Object
Returns the value of attribute idref.
-
#linear ⇒ Object
Returns the value of attribute linear.
-
#properties ⇒ Object
Returns the value of attribute properties.
-
#spine ⇒ Object
Returns the value of attribute spine.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize ⇒ Itemref
constructor
A new instance of Itemref.
-
#item ⇒ Package::Manifest::Item
Item referred by this object.
- #item=(item) ⇒ Object
- #linear? ⇒ true|false
- #page_spread ⇒ "left", ...
- #page_spread=(new_value) ⇒ Object
Constructor Details
#initialize ⇒ Itemref
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
#id ⇒ Object
Returns the value of attribute id.
46 47 48 |
# File 'lib/epub/publication/package/spine.rb', line 46 def id @id end |
#idref ⇒ Object
Returns the value of attribute idref.
46 47 48 |
# File 'lib/epub/publication/package/spine.rb', line 46 def idref @idref end |
#linear ⇒ Object
Returns the value of attribute linear.
46 47 48 |
# File 'lib/epub/publication/package/spine.rb', line 46 def linear @linear end |
#properties ⇒ Object
Returns the value of attribute properties.
48 49 50 |
# File 'lib/epub/publication/package/spine.rb', line 48 def properties @properties end |
#spine ⇒ Object
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 |
#item ⇒ Package::Manifest::Item
Returns item referred by this object.
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
59 60 61 |
# File 'lib/epub/publication/package/spine.rb', line 59 def linear? !! linear end |
#page_spread ⇒ "left", ...
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
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 |