Class: EightBall::Conditions::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/eight_ball/conditions/base.rb

Direct Known Subclasses

Always, List, Never, Opaque, Percentage, Range

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_options = []) ⇒ Base

Returns a new instance of Base.



7
8
9
# File 'lib/eight_ball/conditions/base.rb', line 7

def initialize(_options = [])
  @parameter = nil
end

Instance Attribute Details

#parameterObject

Returns the value of attribute parameter.



5
6
7
# File 'lib/eight_ball/conditions/base.rb', line 5

def parameter
  @parameter
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



15
16
17
# File 'lib/eight_ball/conditions/base.rb', line 15

def ==(other)
  other.class == self.class && other.state == state
end

#hashObject



20
21
22
# File 'lib/eight_ball/conditions/base.rb', line 20

def hash
  state.hash
end

#satisfied?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/eight_ball/conditions/base.rb', line 11

def satisfied?
  raise 'You can never satisfy the Base condition'
end

#to_wireObject

The wire-format hash for this condition. Subclasses declare their fields via #wire_fields; the type is the lower-cased class name, which must match a EightBall::Conditions.by_name key so the condition round-trips.



27
28
29
30
31
32
33
34
# File 'lib/eight_ball/conditions/base.rb', line 27

def to_wire
  wire = { type: self.class.name.split('::').last.downcase }
  wire_fields.each do |field|
    value = public_send(field)
    wire[field.to_s] = value unless value.nil?
  end
  wire
end

#wire_fieldsObject

The attributes this condition serializes, in output order (default: none).



37
38
39
# File 'lib/eight_ball/conditions/base.rb', line 37

def wire_fields
  []
end