Sha256: fd87bf069c2bf41b417dda0e43528bf0233a4970a493a8bf8290eec5322327cb

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

module Lecter
  class HtmlRow
    ARROW = '-> '
    BACKGROUND_INCLUDED_ROW = '#4a4a4a'
    NEW_LINE_SYMBOL = "\n"

    def initialize(row, row_number, row_executable, order_of_executed_lines)
      @row = row
      @row_number = row_number
      @row_executable = row_executable
      @order_of_executed_lines = order_of_executed_lines
    end

    def create
      "<div style='#{style}'><code>#{html_row}</code></div>"
    end

    private

    attr_reader :row, :row_number, :row_executable, :order_of_executed_lines

    def html_row
      [row_number, row, row_calling_order_number].join(' ') + NEW_LINE_SYMBOL
    end

    def row_calling_order_number
      return unless row_executable

      ARROW + order_of_executed_lines
              .each_with_index
              .select { |_, index| order_of_executed_lines[index] == row_number }
              .map { |_, index| index + 1 }
              .join(', ')
    end

    def style
      row_executable ? "background-color: #{BACKGROUND_INCLUDED_ROW};" : nil
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lecter-0.2.0 lib/lecter/html_row.rb