Class: PasteHub::Status

Inherits:
Object
  • Object
show all
Defined in:
lib/pastehub/clientsync.rb

Constant Summary collapse

TIMER_INIT =

second

60

Instance Method Summary collapse

Constructor Details

#initializeStatus

Returns a new instance of Status.



45
46
47
48
49
50
51
# File 'lib/pastehub/clientsync.rb', line 45

def initialize( )
  @comes      = 0
  @online     = false
  @errorFlag  = false
  @timer      = TIMER_INIT
  @curJsonStr = ""
end

Instance Method Details

#iconObject



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/pastehub/clientsync.rb', line 85

def icon( )
  result = if @errorFlag
             "error"
           elsif not @online
             "offline"
           else
             case @comes
             when 0
               "online"
             when 1
               "one"
             when 2
               "two"
             when 3
               "three"
             else
               "threeplus"
             end
           end
  return result
end

#incObject



53
54
55
56
# File 'lib/pastehub/clientsync.rb', line 53

def inc( )
  @comes += 1
  @timer     = TIMER_INIT
end

#resetObject



58
59
60
61
# File 'lib/pastehub/clientsync.rb', line 58

def reset( )
  @comes = 0
  @timer     = TIMER_INIT
end

#setOnline(arg) ⇒ Object



63
64
65
# File 'lib/pastehub/clientsync.rb', line 63

def setOnline( arg )
  @online = arg
end

#tick(delta) ⇒ Object



67
68
69
70
71
72
73
# File 'lib/pastehub/clientsync.rb', line 67

def tick( delta )
  if @timer <= 0
    @comes = 0
  else
    @timer -= delta
  end
end

#updateObject



75
76
77
78
79
80
81
82
83
# File 'lib/pastehub/clientsync.rb', line 75

def update( )
  prev = @curJsonStr
  h = Hash.new
  h[ 'online' ] = @online
  h[ 'error'  ] = @errorFlag
  h[ 'comes'  ] = @comes
  @curJsonStr = JSON.dump( h )
  return [ @curJsonStr, prev ]
end