class OodCore::Job::ArrayIds

Attributes

spec_string[R]

Public Class Methods

new(spec_string) click to toggle source
# File lib/ood_core/job/array_ids.rb, line 15
def initialize(spec_string)
  @spec_string = spec_string
end

Public Instance Methods

ids() click to toggle source
# File lib/ood_core/job/array_ids.rb, line 19
def ids
  @ids ||= parse_spec_string(spec_string)
end

Protected Instance Methods

parse_spec_string(spec_string) click to toggle source
# File lib/ood_core/job/array_ids.rb, line 25
def parse_spec_string(spec_string)
  return [] unless spec_string

  rx = /^(\d+)-?(\d+)?:?(\d+)?%?\d*$/
  spec_string.split(',').reduce([]) do |ids, spec|
    if rx =~ spec
      start = ($1 || 1).to_i
      finish = ($2 || start).to_i
      step = ($3 || 1).to_i
      ids.concat (start..finish).step(step).to_a
    end

    ids
  end
end