Class: EightBall::Conditions::Base
- Inherits:
-
Object
- Object
- EightBall::Conditions::Base
- Defined in:
- lib/eight_ball/conditions/base.rb
Instance Attribute Summary collapse
-
#parameter ⇒ Object
readonly
Returns the value of attribute parameter.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(_options = []) ⇒ Base
constructor
A new instance of Base.
- #satisfied? ⇒ Boolean
-
#to_wire ⇒ Object
The wire-format hash for this condition.
-
#wire_fields ⇒ Object
The attributes this condition serializes, in output order (default: none).
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( = []) @parameter = nil end |
Instance Attribute Details
#parameter ⇒ Object
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 |
#hash ⇒ Object
20 21 22 |
# File 'lib/eight_ball/conditions/base.rb', line 20 def hash state.hash end |
#satisfied? ⇒ 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_wire ⇒ Object
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_fields ⇒ Object
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 |