Class: Elected::Lider
Instance Attribute Summary collapse
-
#created ⇒ Object
readonly
Returns the value of attribute created.
-
#deadline ⇒ Object
readonly
Returns the value of attribute deadline.
-
#diff ⇒ Object
readonly
Returns the value of attribute diff.
-
#info ⇒ Object
readonly
Returns the value of attribute info.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
-
#validity ⇒ Object
readonly
Returns the value of attribute validity.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #current? ⇒ Boolean
-
#initialize(info, timeout) ⇒ Lider
constructor
A new instance of Lider.
- #to_s(type = :short) ⇒ Object (also: #inspect)
Methods included from Logging
#debug, #debug_var, #error, included, #warn
Constructor Details
#initialize(info, timeout) ⇒ Lider
Returns a new instance of Lider.
10 11 12 13 14 15 16 17 18 |
# File 'lib/elected/lider.rb', line 10 def initialize(info, timeout) @info = info @validity = info[:validity] @resource = info[:resource] @value = info[:value] @created = Time.now @deadline = created + (timeout / 1000.0).to_i @diff = @deadline - @created end |
Instance Attribute Details
#created ⇒ Object (readonly)
Returns the value of attribute created.
8 9 10 |
# File 'lib/elected/lider.rb', line 8 def created @created end |
#deadline ⇒ Object (readonly)
Returns the value of attribute deadline.
8 9 10 |
# File 'lib/elected/lider.rb', line 8 def deadline @deadline end |
#diff ⇒ Object (readonly)
Returns the value of attribute diff.
8 9 10 |
# File 'lib/elected/lider.rb', line 8 def diff @diff end |
#info ⇒ Object (readonly)
Returns the value of attribute info.
8 9 10 |
# File 'lib/elected/lider.rb', line 8 def info @info end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
8 9 10 |
# File 'lib/elected/lider.rb', line 8 def resource @resource end |
#validity ⇒ Object (readonly)
Returns the value of attribute validity.
8 9 10 |
# File 'lib/elected/lider.rb', line 8 def validity @validity end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
8 9 10 |
# File 'lib/elected/lider.rb', line 8 def value @value end |
Instance Method Details
#current? ⇒ Boolean
20 21 22 |
# File 'lib/elected/lider.rb', line 20 def current? @deadline > Time.now end |
#to_s(type = :short) ⇒ Object Also known as: inspect
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/elected/lider.rb', line 24 def to_s(type = :short) case type when :full "#<#{self.class.name} " + "resource=#{resource.inspect} " + "value=#{value.inspect} " + "validity=#{validity.inspect} " + "deadline=#{deadline}" + ">" when :yaml to_yaml else %{#<Elected::Lider|#{resource}:#{value[0, 8]}:#{validity}>} end end |