Class: Ankit::Event
- Inherits:
-
Object
- Object
- Ankit::Event
- Defined in:
- lib/ankit/event.rb
Instance Attribute Summary collapse
-
#envelope ⇒ Object
readonly
Returns the value of attribute envelope.
-
#values ⇒ Object
readonly
Returns the value of attribute values.
Class Method Summary collapse
- .for_card(name, verb, env) ⇒ Object
- .from_hash(hash) ⇒ Object
- .parse(text) ⇒ Object
- .sweep(values) ⇒ Object
Instance Method Summary collapse
- #==(other) ⇒ Object
- #best ⇒ Object
- #card? ⇒ Boolean
-
#initialize(env, values) ⇒ Event
constructor
A new instance of Event.
- #maturity ⇒ Object
- #name ⇒ Object
-
#next_round ⇒ Object
def next_round() round + 2**maturity; end.
- #round ⇒ Object
- #to_failed(env) ⇒ Object
- #to_json(*a) ⇒ Object
- #to_passed(env) ⇒ Object
- #type ⇒ Object
- #verb ⇒ Object
- #verb=(val) ⇒ Object
Constructor Details
#initialize(env, values) ⇒ Event
Returns a new instance of Event.
33 34 35 |
# File 'lib/ankit/event.rb', line 33 def initialize(env, values) @envelope, @values = env, values end |
Instance Attribute Details
#envelope ⇒ Object (readonly)
Returns the value of attribute envelope.
20 21 22 |
# File 'lib/ankit/event.rb', line 20 def envelope @envelope end |
#values ⇒ Object (readonly)
Returns the value of attribute values.
20 21 22 |
# File 'lib/ankit/event.rb', line 20 def values @values end |
Class Method Details
.for_card(name, verb, env) ⇒ Object
51 52 53 |
# File 'lib/ankit/event.rb', line 51 def self.for_card(name, verb, env) self.new(env, { "type" => "card", "verb" => verb, "name" => name, "maturity" => 0 }) end |
.from_hash(hash) ⇒ Object
55 |
# File 'lib/ankit/event.rb', line 55 def self.from_hash(hash) Event.new(Envelope.from_hash(hash["envelope"]), hash["values"]); end |
.parse(text) ⇒ Object
56 |
# File 'lib/ankit/event.rb', line 56 def self.parse(text) from_hash(JSON.parse(text)); end |
.sweep(values) ⇒ Object
58 59 60 61 |
# File 'lib/ankit/event.rb', line 58 def self.sweep(values) values.delete("best") if values.include?("best") and values["best"] <= values["maturity"] values end |
Instance Method Details
#==(other) ⇒ Object
37 38 39 |
# File 'lib/ankit/event.rb', line 37 def ==(other) @values == other.values && @envelope == other.envelope end |
#best ⇒ Object
27 |
# File 'lib/ankit/event.rb', line 27 def best() @values["best"] || maturity; end |
#card? ⇒ Boolean
28 |
# File 'lib/ankit/event.rb', line 28 def card?() type == "card"; end |
#maturity ⇒ Object
26 |
# File 'lib/ankit/event.rb', line 26 def maturity() @values["maturity"] || 0; end |
#name ⇒ Object
24 |
# File 'lib/ankit/event.rb', line 24 def name() @values["name"]; end |
#next_round ⇒ Object
def next_round() round + 2**maturity; end
31 |
# File 'lib/ankit/event.rb', line 31 def next_round() round + scaled_maturity; end |
#round ⇒ Object
29 |
# File 'lib/ankit/event.rb', line 29 def round() @envelope.round or 0; end |
#to_failed(env) ⇒ Object
47 48 49 |
# File 'lib/ankit/event.rb', line 47 def to_failed(env) Event.new(env, @values.merge({ "verb" => "failed", "maturity" => -1, "best" => best })) end |
#to_json(*a) ⇒ Object
41 |
# File 'lib/ankit/event.rb', line 41 def to_json(*a) { envelope: @envelope, values: @values }.to_json(*a); end |
#to_passed(env) ⇒ Object
43 44 45 |
# File 'lib/ankit/event.rb', line 43 def to_passed(env) Event.new(env, Event.sweep(@values.merge({ "verb" => "passed", "maturity" => next_maturity }))) end |
#type ⇒ Object
25 |
# File 'lib/ankit/event.rb', line 25 def type() @values["type"]; end |
#verb ⇒ Object
22 |
# File 'lib/ankit/event.rb', line 22 def verb() @values["verb"]; end |
#verb=(val) ⇒ Object
23 |
# File 'lib/ankit/event.rb', line 23 def verb=(val) @values["verb"] = val; end |