Class: EPUB::CFI::Location
- Inherits:
-
Object
- Object
- EPUB::CFI::Location
- Defined in:
- lib/epub/cfi.rb
Instance Attribute Summary collapse
-
#paths ⇒ Object
readonly
Returns the value of attribute paths.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(paths = []) ⇒ Location
constructor
A new instance of Location.
- #initialize_copy(original) ⇒ Object
- #join(*other_paths) ⇒ Object
- #to_fragment ⇒ Object
- #to_s ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(paths = []) ⇒ Location
Returns a new instance of Location.
19 20 21 |
# File 'lib/epub/cfi.rb', line 19 def initialize(paths=[]) @paths = paths end |
Instance Attribute Details
#paths ⇒ Object (readonly)
Returns the value of attribute paths.
17 18 19 |
# File 'lib/epub/cfi.rb', line 17 def paths @paths end |
Instance Method Details
#<=>(other) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/epub/cfi.rb', line 31 def <=>(other) index = 0 other_paths = other.paths cmp = nil paths.each do |path| other_path = other_paths[index] return 1 unless other_path cmp = path <=> other_path break unless cmp == 0 index += 1 end unless cmp == 0 if cmp == 1 and paths[index].offset and other_paths[index + 1] return nil else return cmp end end return nil if paths.last.offset && other_paths[index] return -1 if other_paths[index] 0 end |
#initialize_copy(original) ⇒ Object
23 24 25 |
# File 'lib/epub/cfi.rb', line 23 def initialize_copy(original) @paths = original.paths.collect(&:dup) end |
#join(*other_paths) ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/epub/cfi.rb', line 66 def join(*other_paths) new_paths = paths.dup other_paths.each do |path| new_paths << path end self.class.new(new_paths) end |
#to_fragment ⇒ Object
62 63 64 |
# File 'lib/epub/cfi.rb', line 62 def to_fragment "epubcfi(#{self})" end |
#to_s ⇒ Object
58 59 60 |
# File 'lib/epub/cfi.rb', line 58 def to_s paths.join('!') end |
#type ⇒ Object
27 28 29 |
# File 'lib/epub/cfi.rb', line 27 def type @paths.last.type end |