Sha256: 8af48048048dded6a9dd42fa58aef5056eb67ea3b1a544f6047cbb194f697dc8

Contents?: true

Size: 863 Bytes

Versions: 6

Compression:

Stored size: 863 Bytes

Contents

# frozen_string_literal: true

module Nocode
  module Steps
    module Dataset
      # Slice a dataset and keep on the entries between start_index and end_index, inclusively.
      # If start_index is not provided then it defaults to 0.
      # If end_index is not provided then it defaults to the end of the dataset.
      class Range < Step
        option :end_index,
               :register,
               :start_index

        def perform
          registers[register_option] = array(registers[register_option])

          registers[register_option] = registers[register_option][start_index..end_index]
        end

        private

        def start_index
          start_index_option.nil? ? 0 : start_index_option.to_i
        end

        def end_index
          end_index_option.nil? ? -1 : end_index_option.to_i
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
nocode-0.0.10 lib/nocode/steps/dataset/range.rb
nocode-0.0.9 lib/nocode/steps/dataset/range.rb
nocode-0.0.8 lib/nocode/steps/dataset/range.rb
nocode-0.0.7 lib/nocode/steps/dataset/range.rb
nocode-0.0.6 lib/nocode/steps/dataset/range.rb
nocode-0.0.5 lib/nocode/steps/dataset/range.rb