Sha256: 3aaa6548adf9138cc32f25f756da2ebe8d287c8eac18eac57c135c7fba0b8129

Contents?: true

Size: 866 Bytes

Versions: 90

Compression:

Stored size: 866 Bytes

Contents

require 'exercise_cases'

class TransposeCase < OpenStruct
  def test_name
    "test_#{description.tr(' ', '_')}"
  end

  def skipped
    index.zero? ? '# skip' : 'skip'
  end

  def workload
    'Transpose.transpose(input)'
  end

  def expect
    indented_heredoc(expected, 'EXPECTED')
  end

  def input_text
    indented_heredoc(input, 'INPUT')
  end

  private

  def indented_heredoc(string, delimiter)
    [
      "<<-#{delimiter}.gsub(/^ {6}/, '')",
      indent_lines(string),
      indent_line(delimiter)
    ].join("\n")
  end

  def indent_lines(lines, indent = 3)
    lines.map { |line| indent_line(line, indent) }.join("\n")
  end

  def indent_line(line, indent = 2)
    ' ' * indent * 2 + line
  end
end

TransposeCases = proc do |data|
  JSON.parse(data)['cases'].map.with_index do |row, i|
    TransposeCase.new(row.merge('index' => i))
  end
end

Version data entries

90 entries across 90 versions & 1 rubygems

Version Path
trackler-2.0.8.16 tracks/ruby/lib/transpose_cases.rb
trackler-2.0.8.15 tracks/ruby/lib/transpose_cases.rb
trackler-2.0.8.14 tracks/ruby/lib/transpose_cases.rb
trackler-2.0.8.13 tracks/ruby/lib/transpose_cases.rb
trackler-2.0.8.12 tracks/ruby/lib/transpose_cases.rb
trackler-2.0.8.11 tracks/ruby/lib/transpose_cases.rb
trackler-2.0.8.10 tracks/ruby/lib/transpose_cases.rb
trackler-2.0.8.9 tracks/ruby/lib/transpose_cases.rb
trackler-2.0.8.8 tracks/ruby/lib/transpose_cases.rb
trackler-2.0.8.7 tracks/ruby/lib/transpose_cases.rb
trackler-2.0.8.6 tracks/ruby/lib/transpose_cases.rb
trackler-2.0.8.5 tracks/ruby/lib/transpose_cases.rb
trackler-2.0.8.4 tracks/ruby/lib/transpose_cases.rb
trackler-2.0.8.3 tracks/ruby/lib/transpose_cases.rb
trackler-2.0.8.2 tracks/ruby/lib/transpose_cases.rb
trackler-2.0.8.1 tracks/ruby/lib/transpose_cases.rb
trackler-2.0.7.0 tracks/ruby/lib/transpose_cases.rb
trackler-2.0.6.44 tracks/ruby/lib/transpose_cases.rb
trackler-2.0.6.43 tracks/ruby/lib/transpose_cases.rb
trackler-2.0.6.42 tracks/ruby/lib/transpose_cases.rb