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_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
# File 'lib/tarka_matchers/formatters/selected.rb', line 6

def self.selected original, selected
  indexes = []
  selected.each_slice(2){ |si,ei| indexes << (si..ei).to_a }
  indexes.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#{RESET}" 
end