Sha256: 83364357da7ec386e13df8dedb6f96f0b59b8123d16db8f69cb45346e1745e2c

Contents?: true

Size: 796 Bytes

Versions: 65

Compression:

Stored size: 796 Bytes

Contents

# -*- coding: utf-8 -*-

require 'milkode/common/string_snip'

class GrenSnip
  MAX_LINE_SIZE = 256
  HEADER_SIZE = 32
  MARGIN_SIZE = 32
  DELIMITER = '<<snip>>'

  def self.snip(str, match_datas)
    return str if (str.size <= MAX_LINE_SIZE)

    ranges = []
    ranges << (0..HEADER_SIZE-1)
    ranges << (-HEADER_SIZE..-1)

    match_datas.each do |m|
      ranges << (m.begin(0)-MARGIN_SIZE..m.end(0)+MARGIN_SIZE)
    end

    snipper = StringSnip.new(MAX_LINE_SIZE, DELIMITER)
    return snipper.snip(str, ranges)
  end

  def self.coloring(line, match_datas)
    match_datas.each do |m|
      line = line.split(m[0]).join(HighLine::ON_GREEN + m[0] + HighLine::CLEAR)
    end
    
    line = line.split(DELIMITER).join(HighLine::ON_CYAN + DELIMITER + HighLine::CLEAR)

    line
  end
end


Version data entries

65 entries across 65 versions & 1 rubygems

Version Path
milkode-1.8.9.2 lib/milkode/common/grensnip.rb
milkode-1.8.9.1 lib/milkode/common/grensnip.rb
milkode-1.8.9 lib/milkode/common/grensnip.rb
milkode-1.8.8 lib/milkode/common/grensnip.rb
milkode-1.8.7 lib/milkode/common/grensnip.rb
milkode-1.8.6 lib/milkode/common/grensnip.rb
milkode-1.8.5 lib/milkode/common/grensnip.rb
milkode-1.8.4 lib/milkode/common/grensnip.rb
milkode-1.8.3 lib/milkode/common/grensnip.rb
milkode-1.8.2 lib/milkode/common/grensnip.rb
milkode-1.8.1 lib/milkode/common/grensnip.rb
milkode-1.8.0 lib/milkode/common/grensnip.rb
milkode-1.7.1 lib/milkode/common/grensnip.rb
milkode-1.7.0 lib/milkode/common/grensnip.rb
milkode-1.6.1 lib/milkode/common/grensnip.rb
milkode-1.6.0 lib/milkode/common/grensnip.rb
milkode-1.5.0 lib/milkode/common/grensnip.rb
milkode-1.4.0 lib/milkode/common/grensnip.rb
milkode-1.3.0 lib/milkode/common/grensnip.rb
milkode-1.2.0 lib/milkode/common/grensnip.rb