lib/epub/cfi.rb in epub-parser-0.2.3 vs lib/epub/cfi.rb in epub-parser-0.2.4

- old
+ new

@@ -39,11 +39,11 @@ break unless cmp == 0 index += 1 end unless cmp == 0 - if cmp == 1 and other_paths[index + 1] + if cmp == 1 and paths[index].offset and other_paths[index + 1] return nil else return cmp end end @@ -180,29 +180,38 @@ @fragment_cache ||= "epubcfi(#{@parent},#{@start},#{@end})".freeze end end class Step - attr_reader :step, :assertion + attr_reader :value, :assertion + alias step value - def initialize(step, assertion=nil) - @step, @assertion = step, assertion + def initialize(value, assertion=nil) + @value, @assertion = value, assertion @string_cache = nil end def initialize_copy(original) - @step = original.step + @value = original.value @assertion = original.assertion.dup if original.assertion end def to_s - @string_cache ||= "/#{step}#{assertion}".freeze # need escape? + @string_cache ||= "/#{value}#{assertion}".freeze # need escape? end def <=>(other) - step <=> other.step + value <=> other.value end + + def element? + value.even? + end + + def character_data? + value.odd? + end end class IDAssertion attr_reader :id, :parameters @@ -245,22 +254,23 @@ @string_cache.freeze end end class CharacterOffset - attr_reader :offset, :assertion + attr_reader :value, :assertion + alias offset value - def initialize(offset, assertion=nil) - @offset, @assertion = offset, assertion + def initialize(value, assertion=nil) + @value, @assertion = value, assertion @string_cache = nil end def to_s - @string_cache ||= ":#{offset}#{assertion}".freeze # need escape? + @string_cache ||= ":#{value}#{assertion}".freeze # need escape? end def <=>(other) - offset <=> other.offset + value <=> other.value end end class TemporalSpatialOffset attr_reader :temporal, :x, :y, :assertion