Class: Elected::Lider

Inherits:
Object show all
Includes:
Logging
Defined in:
lib/elected/lider.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#createdObject (readonly)

Returns the value of attribute created.



8
9
10
# File 'lib/elected/lider.rb', line 8

def created
  @created
end

#deadlineObject (readonly)

Returns the value of attribute deadline.



8
9
10
# File 'lib/elected/lider.rb', line 8

def deadline
  @deadline
end

#diffObject (readonly)

Returns the value of attribute diff.



8
9
10
# File 'lib/elected/lider.rb', line 8

def diff
  @diff
end

#infoObject (readonly)

Returns the value of attribute info.



8
9
10
# File 'lib/elected/lider.rb', line 8

def info
  @info
end

#resourceObject (readonly)

Returns the value of attribute resource.



8
9
10
# File 'lib/elected/lider.rb', line 8

def resource
  @resource
end

#validityObject (readonly)

Returns the value of attribute validity.



8
9
10
# File 'lib/elected/lider.rb', line 8

def validity
  @validity
end

#valueObject (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

Returns:

  • (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