lib/emendate/segment_set/segment_set.rb
# returns the first sequence of segments matching the pattern of types passed in as an Array
returns the first sequence of segments matching the pattern of types passed in as an Array
returns the first sequence of segments matching the pattern of types passed in as an Array
def extract(*args)
      args.flatten!
      segsize = args.length
      return self.class.new if segments.length < segsize
      if segments.length == segsize
        result = self.class.new(segments)
        return result
      end
      tails = segments.select{ |t| t.type == args[-1] }
      return self.class.new if tails.empty?
      segment = []
      tails.each do |tail|
        if segment.empty?
          tail_i = segments.find_index(tail)
          head_i = tail_i - segsize + 1
          seg = self.class.new(segments[head_i..tail_i])
          segment = seg.types == args ? seg : []
        end
      end
      result = self.class.new
      segment.each{ |s| result << s }
      result
    end
def extract ( * args ) args . flatten! segsize = args . length return self . class . new if segments . length < segsize if segments . length == segsize result = self . class . new ( segments ) return result end tails = segments . select { | t | t . type == args [ - 1 ] } return self . class . new if tails . empty? segment = [ ] tails . each do | tail | if segment . empty? tail_i = segments . find_index ( tail ) head_i = tail_i - segsize + 1 seg = self . class . new ( segments [ head_i .. tail_i ] ) segment = seg . types == args ? seg : [ ] end end result = self . class . new segment . each { | s | result << s } result end
returns the first sequence of segments matching the pattern of types passed in as an Array
returns the first sequence of segments matching the pattern of types passed in as an Array
args
<not_specific>