Class: Spinach::Orderers::Random
- Inherits:
-
Object
- Object
- Spinach::Orderers::Random
- Defined in:
- lib/spinach/orderers/random.rb
Instance Attribute Summary collapse
-
#seed ⇒ Object
readonly
Returns the value of attribute seed.
Instance Method Summary collapse
-
#attach_summary(io) ⇒ Object
Output the randomization seed in the report summary.
-
#initialize(seed:) ⇒ Random
constructor
A new instance of Random.
-
#order(items) ⇒ Object
Returns a reordered version of the provided array.
Constructor Details
#initialize(seed:) ⇒ Random
Returns a new instance of Random.
8 9 10 |
# File 'lib/spinach/orderers/random.rb', line 8 def initialize(seed:) @seed = seed.to_s end |
Instance Attribute Details
#seed ⇒ Object (readonly)
Returns the value of attribute seed.
6 7 8 |
# File 'lib/spinach/orderers/random.rb', line 6 def seed @seed end |
Instance Method Details
#attach_summary(io) ⇒ Object
Output the randomization seed in the report summary.
18 19 20 |
# File 'lib/spinach/orderers/random.rb', line 18 def attach_summary(io) io.puts("Randomized with seed #{seed}\n\n") end |
#order(items) ⇒ Object
Returns a reordered version of the provided array
28 29 30 31 32 |
# 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 |