Class: EPUB::CFI::Path

Inherits:
Object
  • Object
show all
Defined in:
lib/epub/cfi.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(steps = [], offset = nil) ⇒ Path

Returns a new instance of Path.



118
119
120
# File 'lib/epub/cfi.rb', line 118

def initialize(steps=[], offset=nil)
  @steps, @offset = steps, offset
end

Instance Attribute Details

#offsetObject (readonly)

Returns the value of attribute offset.



116
117
118
# File 'lib/epub/cfi.rb', line 116

def offset
  @offset
end

#stepsObject (readonly)

Returns the value of attribute steps.



116
117
118
# File 'lib/epub/cfi.rb', line 116

def steps
  @steps
end

Instance Method Details

#<=>(other) ⇒ Object



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/epub/cfi.rb', line 131

def <=>(other)
  other_steps = other.steps
  index = 0
  steps.each do |step|
    other_step = other_steps[index]
    return 1 unless other_step
    cmp = step <=> other_step
    return cmp unless cmp == 0
    index += 1
  end

  return -1 if other_steps[index]

  other_offset = other.offset
  if offset
    if other_offset
      offset <=> other_offset
    else
      1
    end
  else
    if other_offset
      -1
    else
      0
    end
  end
end

#initialize_copy(original) ⇒ Object



122
123
124
125
# File 'lib/epub/cfi.rb', line 122

def initialize_copy(original)
  @steps = original.steps.collect(&:dup)
  @offset = original.offset.dup if original.offset
end

#to_sObject



127
128
129
# File 'lib/epub/cfi.rb', line 127

def to_s
  @string_cache ||= (steps.join + offset.to_s)
end