Class: EPUB::CFI::TemporalSpatialOffset

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(temporal = nil, x = nil, y = nil, assertion = nil) ⇒ TemporalSpatialOffset

Returns a new instance of TemporalSpatialOffset.

Raises:

  • (RangeError)

279
280
281
282
283
284
285
# File 'lib/epub/cfi.rb', line 279

def initialize(temporal=nil, x=nil, y=nil, assertion=nil)
  raise RangeError, "dimension must be in 0..100 but passed #{x}" unless (0.0..100.0).cover?(x) if x
  raise RangeError, "dimension must be in 0..100 but passed #{y}" unless (0.0..100.0).cover?(y) if y
  warn "Assertion is passed to #{__class__} but cannot know how to handle with it: #{assertion}" if assertion
  @temporal, @x, @y, @assertion = temporal, x, y, assertion
  @string_cache
end

Instance Attribute Details

#assertionObject (readonly)

Returns the value of attribute assertion


277
278
279
# File 'lib/epub/cfi.rb', line 277

def assertion
  @assertion
end

#temporalObject (readonly)

Returns the value of attribute temporal


277
278
279
# File 'lib/epub/cfi.rb', line 277

def temporal
  @temporal
end

#xObject (readonly)

Returns the value of attribute x


277
278
279
# File 'lib/epub/cfi.rb', line 277

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y


277
278
279
# File 'lib/epub/cfi.rb', line 277

def y
  @y
end

Instance Method Details

#<=>(other) ⇒ Object

Note:

should split the class to spatial offset and temporal-spatial offset?


296
297
298
299
300
301
302
303
304
305
306
307
308
# File 'lib/epub/cfi.rb', line 296

def <=>(other)
  return -1 if temporal.nil? and other.temporal
  return 1 if temporal and other.temporal.nil?
  cmp = temporal <=> other.temporal
  return cmp unless cmp == 0
  return -1 if y.nil? and other.y
  return 1 if y and other.y.nil?
  cmp = y <=> other.y
  return cmp unless cmp == 0
  return -1 if x.nil? and other.x
  return 1 if x and other.x.nil?
  cmp = x <=> other.x
end

#to_sObject


287
288
289
290
291
292
293
# File 'lib/epub/cfi.rb', line 287

def to_s
  return @string_cache if @string_cache
  @string_cache = ''
  @string_cache << "~#{temporal}" if temporal
  @string_cache << "@#{x}:#{y}" if x or y
  @string_cache.freeze
end