Method: QDA::Coding#intersect

Defined in:
lib/weft/coding.rb

#intersect(other) ⇒ Object Also known as: %

returns the code representing the intersection of self and other returns nil if there is no overlap



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/weft/coding.rb', line 58

def intersect(other)
  # this represents self, possibly coerced into a different class

  this, other = prepare_args(other)
  unless this.overlap?(other)
    return nil
  end
  sorted = QDA::CodeSet[ this, other ].sort
  this_start = [ other.offset, this.offset ].max
  this_end = [other.end, this.end ].min
  fragment = sorted[0][this_start, this_end - this_start ]
end