Sha256: 1a1cc265c43f3e44f7eb0608add2201d0289ef7f92db6cb17ca765c1d4310512

Contents?: true

Size: 1.03 KB

Versions: 222

Compression:

Stored size: 1.03 KB

Contents

module Generator
  class ExerciseCase
    module CaseHelpers
      protected

      # indent multi line workloads
      #
      #   indent_lines(
      #     [
      #       "string = #{input.inspect}",
      #       "#{assert} Isogram.is_isogram?(string)"
      #     ], 4
      #   )
      def indent_lines(code, depth, separator = "\n")
        code.join(separator + ' ' * depth)
      end

      # indent multi line workloads with (unindented) blank lines
      #
      #   indent_text(4, text)
      def indent_text(depth, text)
        text.lines.reduce do |obj, line|
          obj << (line == "\n" ? line : ' ' * depth + line)
        end
      end

      # generate heredoc (as part of workload) with optional indentation
      #
      #    indent_heredoc(["foo", "bar"], 'TEXT', 1)
      def indent_heredoc(lines, delimiter, depth = 0, delimiter_method = nil)
        [
          "<<-#{delimiter}#{delimiter_method}",
          lines.map { |line| ' ' * depth + line }.join("\n"),
          delimiter
        ].join("\n")
      end
    end
  end
end

Version data entries

222 entries across 222 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/ruby/lib/generator/exercise_case/case_helpers.rb
trackler-2.2.1.179 tracks/ruby/lib/generator/exercise_case/case_helpers.rb
trackler-2.2.1.178 tracks/ruby/lib/generator/exercise_case/case_helpers.rb
trackler-2.2.1.177 tracks/ruby/lib/generator/exercise_case/case_helpers.rb
trackler-2.2.1.176 tracks/ruby/lib/generator/exercise_case/case_helpers.rb
trackler-2.2.1.175 tracks/ruby/lib/generator/exercise_case/case_helpers.rb
trackler-2.2.1.174 tracks/ruby/lib/generator/exercise_case/case_helpers.rb
trackler-2.2.1.173 tracks/ruby/lib/generator/exercise_case/case_helpers.rb
trackler-2.2.1.172 tracks/ruby/lib/generator/exercise_case/case_helpers.rb
trackler-2.2.1.171 tracks/ruby/lib/generator/exercise_case/case_helpers.rb
trackler-2.2.1.170 tracks/ruby/lib/generator/exercise_case/case_helpers.rb
trackler-2.2.1.169 tracks/ruby/lib/generator/exercise_case/case_helpers.rb
trackler-2.2.1.167 tracks/ruby/lib/generator/exercise_case/case_helpers.rb
trackler-2.2.1.166 tracks/ruby/lib/generator/exercise_case/case_helpers.rb
trackler-2.2.1.165 tracks/ruby/lib/generator/exercise_case/case_helpers.rb
trackler-2.2.1.164 tracks/ruby/lib/generator/exercise_case/case_helpers.rb
trackler-2.2.1.163 tracks/ruby/lib/generator/exercise_case/case_helpers.rb
trackler-2.2.1.162 tracks/ruby/lib/generator/exercise_case/case_helpers.rb
trackler-2.2.1.161 tracks/ruby/lib/generator/exercise_case/case_helpers.rb
trackler-2.2.1.160 tracks/ruby/lib/generator/exercise_case/case_helpers.rb