Class: GrenSnip
- Inherits:
-
Object
- Object
- GrenSnip
- Defined in:
- lib/common/grensnip.rb
Constant Summary collapse
- MAX_LINE_SIZE =
256
- HEADER_SIZE =
32
- MARGIN_SIZE =
32
- DELIMITER =
'<<snip>>'
Class Method Summary collapse
Class Method Details
.coloring(line, match_datas) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/common/grensnip.rb', line 26 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 |
.snip(str, match_datas) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/common/grensnip.rb', line 11 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 |