Module: TraceVisualization::Mapping
- Defined in:
- lib/trace_visualization/mapping.rb
Defined Under Namespace
Classes: Item
Constant Summary collapse
- PATTERNS =
{ "id" => [ /(?<value>\[\d{3,}\])/ ], "ip" => [ /(?<value>(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))/ ], "time" => [ /(?<value>\[\d{2} [a-zA-Z]{3} \d{4} \d{2}\:\d{2}\:\d{2}\])/ ] }
Class Method Summary collapse
- .match(str, type, pattern, map, ppos, itemByPos) ⇒ Object
- .parse(str) ⇒ Object
- .restore(array) ⇒ Object
Class Method Details
.match(str, type, pattern, map, ppos, itemByPos) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/trace_visualization/mapping.rb', line 97 def self.match(str, type, pattern, map, ppos, itemByPos) pos = 0 limit = 1000 while (m = pattern.match(str, pos)) value = m[:value] pos = m.begin(0) ppos << pos map[value] = Item.new(value, type) unless map[value] itemByPos[pos] = map[value] pos += value.size end end |
.parse(str) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/trace_visualization/mapping.rb', line 64 def self.parse(str) map = {} ppos = [] itemByPos = {} PATTERNS.each do |type, patterns| patterns.each do |pattern| match(str, type, pattern, map, ppos, itemByPos) end end i, j = 0, 0 result = [] ppos.sort! while i < str.size if i == ppos[j] item = itemByPos[ppos[j]] result << item i += item.length j += 1 else result << Item.new(str[i], "char") i += 1 end end TraceVisualization::Reorder.process(result) result end |
.restore(array) ⇒ Object
115 116 117 |
# File 'lib/trace_visualization/mapping.rb', line 115 def self.restore(array) array.inject("") { |res, c| res += c.to_str } end |