Class: TerminalPing

Inherits:
Object
  • Object
show all
Extended by:
Machinist::Machinable
Includes:
ActiveAttr::Model, ActiveModel::Callbacks, ActiveModel::Translation
Defined in:
app/models/terminal_ping.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.i18n_scopeObject



7
8
9
# File 'app/models/terminal_ping.rb', line 7

def self.i18n_scope
  :activerecord
end

Instance Method Details

#card_reader_errorObject



83
84
85
# File 'app/models/terminal_ping.rb', line 83

def card_reader_error
  error(:card_reader)
end

#card_reader_modelObject



91
92
93
# File 'app/models/terminal_ping.rb', line 91

def card_reader_model
  value 'model', :card_reader
end

#card_reader_versionObject



87
88
89
# File 'app/models/terminal_ping.rb', line 87

def card_reader_version
  value 'version', :card_reader
end

#cash_acceptor_errorObject



107
108
109
# File 'app/models/terminal_ping.rb', line 107

def cash_acceptor_error
  error(:cash_acceptor)
end

#cash_acceptor_modelObject



115
116
117
# File 'app/models/terminal_ping.rb', line 115

def cash_acceptor_model
  value 'model', :cash_acceptor
end

#cash_acceptor_versionObject



111
112
113
# File 'app/models/terminal_ping.rb', line 111

def cash_acceptor_version
  value 'version', :cash_acceptor
end

#cash_countObject



79
80
81
# File 'app/models/terminal_ping.rb', line 79

def cash_count
  banknotes.values.map{|x| x.to_i}.sum
end

#cash_sumObject



75
76
77
# File 'app/models/terminal_ping.rb', line 75

def cash_sum
  banknotes.collect{|k,v| k.to_i*v.to_i}.sum
end

#error(*hardware) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
# File 'app/models/terminal_ping.rb', line 44

def error(*hardware)
  if hardware.count == 1
    v = value('error', hardware.first)
    return v.nil? ? nil : v.to_i
  else
    return hardware.map do |x|
      v = value('error', x)
      v.nil? ? nil : v.to_i
    end
  end
end

#modem_balanceObject



139
140
141
# File 'app/models/terminal_ping.rb', line 139

def modem_balance
  modem['balance']
end

#modem_errorObject



131
132
133
# File 'app/models/terminal_ping.rb', line 131

def modem_error
  error(:modem)
end

#modem_modelObject



147
148
149
# File 'app/models/terminal_ping.rb', line 147

def modem_model
  value 'model', :modem
end

#modem_signal_levelObject



143
144
145
# File 'app/models/terminal_ping.rb', line 143

def modem_signal_level
  modem['signal_level']
end

#modem_versionObject



135
136
137
# File 'app/models/terminal_ping.rb', line 135

def modem_version
  value 'version', :modem
end

#ok?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'app/models/terminal_ping.rb', line 71

def ok?
  condition == 'ok'
end

#printer_errorObject



119
120
121
# File 'app/models/terminal_ping.rb', line 119

def printer_error
  error(:printer)
end

#printer_modelObject



127
128
129
# File 'app/models/terminal_ping.rb', line 127

def printer_model
  value 'model', :printer
end

#printer_versionObject



123
124
125
# File 'app/models/terminal_ping.rb', line 123

def printer_version
  value 'version', :printer
end

#valid?(*args) ⇒ Boolean

Returns:

  • (Boolean)


56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/models/terminal_ping.rb', line 56

def valid?(*args)
  codes = error(*Terminal::HARDWARE).compact

  self.condition = 
    if codes.blank?
      'ok'
    elsif codes.min >= 1000
      'warning'
    else
      'error'
    end

  super
end

#value(field, hardware) ⇒ Object



39
40
41
42
# File 'app/models/terminal_ping.rb', line 39

def value(field, hardware)
  source = (send(hardware) || {}) rescue {}
  source[field].blank? ? nil : source[field]
end

#watchdog_errorObject



95
96
97
# File 'app/models/terminal_ping.rb', line 95

def watchdog_error
  error(:watchdog)
end

#watchdog_modelObject



103
104
105
# File 'app/models/terminal_ping.rb', line 103

def watchdog_model
  value 'model', :watchdog
end

#watchdog_versionObject



99
100
101
# File 'app/models/terminal_ping.rb', line 99

def watchdog_version
  value 'version', :watchdog
end