Class: TarkaMatchers::Formatters::Selected

Inherits:
Object
  • Object
show all
Includes:
Styles
Defined in:
lib/tarka_matchers/formatters/selected.rb

Constant Summary

Constants included from Styles

TarkaMatchers::Formatters::Styles::BLACK_ON_GREEN, TarkaMatchers::Formatters::Styles::GREEN_F, TarkaMatchers::Formatters::Styles::L_GREEN_F, TarkaMatchers::Formatters::Styles::RED_BLOCK, TarkaMatchers::Formatters::Styles::RED_F, TarkaMatchers::Formatters::Styles::RESET, TarkaMatchers::Formatters::Styles::WHITE_BLOCK, TarkaMatchers::Formatters::Styles::WHITE_F, TarkaMatchers::Formatters::Styles::WHITE_ON_RED, TarkaMatchers::Formatters::Styles::YELLOW_F

Class Method Summary collapse

Class Method Details

.selected(original, selected) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/tarka_matchers/formatters/selected.rb', line 6

def self.selected original, selected
	indexes, actual_boundaries = [], []
	selected.each_slice(2) do |si,ei| 
		indexes << (si..ei).to_a
		actual_boundaries  << [si,ei]
	end
	indexes.flatten!
	actual_boundaries.flatten!

	original_line = "#{GREEN_F}Original: #{BLACK_ON_GREEN}#{original}#{RESET}"
	selected_line = "\n#{RESET}#{RED_F}Selected: "
	selects = 0
	original.split('').each_with_index do |v,i|
		if indexes.include? i
			selects += 1
			selected_line << "#{BLACK_ON_GREEN}#{v}"
		else
			selected_line << "#{RED_BLOCK}"
		end
	end

	matched = ((selects.to_f/original.length) * 100).round 3
	"\n\n#{original_line}#{selected_line}#{RESET}#{RED_F} - #{matched}% matched.\n#{RED_F}Bounds:   #{actual_boundaries}\n#{WHITE_F}Formatter: #{self.name}#{RESET}" 
end