class Spinach::Orderers::Random

Attributes

seed[R]

Public Class Methods

new(seed:) click to toggle source
# File lib/spinach/orderers/random.rb, line 8
def initialize(seed:)
  @seed = seed.to_s
end

Public Instance Methods

attach_summary(io) click to toggle source

Output the randomization seed in the report summary.

@param [IO] io

Output buffer for report.

@api public

# File lib/spinach/orderers/random.rb, line 18
def attach_summary(io)
  io.puts("Randomized with seed #{seed}\n\n")
end
order(items) click to toggle source

Returns a reordered version of the provided array

@param [Array] items

Items to order

@api public

# File lib/spinach/orderers/random.rb, line 28
def order(items)
  items.sort_by do |item|
    Digest::MD5.hexdigest(seed + item.ordering_id)
  end
end