Sha256: 4d1d25c0fedf3b885a011509090567d6f89104a21762e7befc60aec8b40067c3

Contents?: true

Size: 916 Bytes

Versions: 63

Compression:

Stored size: 916 Bytes

Contents

class SayCase < OpenStruct
  def test_name
    'test_%s' % description.tr(' ,-', '_').downcase
  end

  def workload
    [
      "question = #{underscore_format(input)}",
      indent(4, assertion),
    ].join("\n")
  end

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

  private

  def indent(size, lines)
    lines.lines.each_with_object('') { |line, obj| obj << ' ' * size + line }
  end

  def assertion
    return error_assertion if expected == -1

    "assert_equal('#{expected}', Say.new(question).in_english)"
  end

  def error_assertion
    [
      'assert_raises ArgumentError do',
      indent(2, 'Say.new(question).in_english'),
      'end',
    ].join("\n")
  end

  def underscore_format(number)
    number.to_s.reverse.gsub(/...(?=.)/, '\&_').reverse
  end
end

SayCases = proc do |data|
  JSON.parse(data)['cases'].map.with_index do |row, i|
    SayCase.new(row.merge(index: i))
  end
end

Version data entries

63 entries across 63 versions & 1 rubygems

Version Path
trackler-2.1.0.1 tracks/ruby/lib/say_cases.rb
trackler-2.1.0.0 tracks/ruby/lib/say_cases.rb
trackler-2.0.8.55 tracks/ruby/lib/say_cases.rb
trackler-2.0.8.54 tracks/ruby/lib/say_cases.rb
trackler-2.0.8.53 tracks/ruby/lib/say_cases.rb
trackler-2.0.8.52 tracks/ruby/lib/say_cases.rb
trackler-2.0.8.51 tracks/ruby/lib/say_cases.rb
trackler-2.0.8.50 tracks/ruby/lib/say_cases.rb
trackler-2.0.8.49 tracks/ruby/lib/say_cases.rb
trackler-2.0.8.48 tracks/ruby/lib/say_cases.rb
trackler-2.0.8.47 tracks/ruby/lib/say_cases.rb
trackler-2.0.8.46 tracks/ruby/lib/say_cases.rb
trackler-2.0.8.45 tracks/ruby/lib/say_cases.rb
trackler-2.0.8.44 tracks/ruby/lib/say_cases.rb
trackler-2.0.8.43 tracks/ruby/lib/say_cases.rb
trackler-2.0.8.42 tracks/ruby/lib/say_cases.rb
trackler-2.0.8.41 tracks/ruby/lib/say_cases.rb
trackler-2.0.8.40 tracks/ruby/lib/say_cases.rb
trackler-2.0.8.39 tracks/ruby/lib/say_cases.rb
trackler-2.0.8.38 tracks/ruby/lib/say_cases.rb