Class: Randsum::ReplacerTarget

Inherits:
Object
  • Object
show all
Defined in:
lib/randsum/filters/replacers/replacer_targets/replacer_target.rb

Direct Known Subclasses

ReplacerTargetAll

Constant Summary collapse

ALL =
:all

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target, roll:) ⇒ ReplacerTarget

Returns a new instance of ReplacerTarget.



17
18
19
20
# File 'lib/randsum/filters/replacers/replacer_targets/replacer_target.rb', line 17

def initialize(target, roll:)
  @target = target
  @roll = roll
end

Instance Attribute Details

#rollObject (readonly)

Returns the value of attribute roll.



4
5
6
# File 'lib/randsum/filters/replacers/replacer_targets/replacer_target.rb', line 4

def roll
  @roll
end

#targetObject (readonly)

Returns the value of attribute target.



4
5
6
# File 'lib/randsum/filters/replacers/replacer_targets/replacer_target.rb', line 4

def target
  @target
end

Class Method Details

.for(target, roll:) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/randsum/filters/replacers/replacer_targets/replacer_target.rb', line 6

def self.for(target, roll:)
  case target
  when ALL
    ReplacerTargetAll
  when nil
    ReplacerTargetAll
  else
    ReplacerTarget
  end.new(target, roll: roll)
end

Instance Method Details

#matchObject



22
23
24
25
26
# File 'lib/randsum/filters/replacers/replacer_targets/replacer_target.rb', line 22

def match
  roll.result.select do |r|
    r == target
  end
end