Class: Dovado::Router::Info
- Inherits:
-
Object
- Object
- Dovado::Router::Info
- Includes:
- Celluloid
- Defined in:
- lib/dovado/router/info.rb,
lib/dovado/router/info/signal.rb,
lib/dovado/router/info/operator.rb,
lib/dovado/router/info/operator/telia.rb
Overview
Router information.
Defined Under Namespace
Instance Attribute Summary collapse
-
#connected_devices ⇒ Array<String>
readonly
Get connected devices.
-
#connection ⇒ String
readonly
Get the currently active connection.
-
#date ⇒ Date
readonly
Get the current date on the router.
-
#external_ip ⇒ IPAddr
readonly
Get the external IP address of the router.
-
#gps_lat ⇒ Float
readonly
Get the GPS latitude.
-
#gps_long ⇒ Float
readonly
Get the GPS longitude.
-
#gps_type ⇒ String
readonly
Get the GPS type.
-
#modem_status ⇒ String
readonly
Get the current state of the connected modem.
-
#product_name ⇒ String
readonly
Get the product name.
-
#signal_strength ⇒ Info::Signal
readonly
Get the current signal strength information.
-
#sms ⇒ Sms
readonly
Get the sms object.
-
#sunrise ⇒ Time
readonly
Get the sunrise at the current location.
-
#sunset ⇒ Time
readonly
Get sunset at the current location.
-
#time ⇒ Time
readonly
Get the current time on the router.
-
#traffic_modem_rx ⇒ Integer
readonly
Get the number of kilobytes read from the internet since last traffic counter reset.
-
#traffic_modem_tx ⇒ Integer
readonly
Get the number of kilobytes sent to the internet since last traffic counter reset.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Fetch an entry from the Info object.
-
#create_from_string(data_string = nil) ⇒ Object
Create a new Info object from a
String. -
#has_key?(key) ⇒ Boolean
Check if the Info object has a given key.
-
#initialize(args = nil) ⇒ Info
constructor
Create a new Info object.
-
#keys ⇒ Array<Symbol>
Fetch the list of entries in the Info object.
-
#valid? ⇒ Boolean
Determine if this info object is valid.
Constructor Details
#initialize(args = nil) ⇒ Info
Create a new Dovado::Router::Info object.
117 118 119 120 121 122 123 124 125 |
# File 'lib/dovado/router/info.rb', line 117 def initialize(args=nil) # Defaults @data = ThreadSafe::Cache.new @last_update = nil unless args.nil? @data = args end end |
Instance Attribute Details
#connected_devices ⇒ Array<String> (readonly)
Get connected devices
112 113 114 |
# File 'lib/dovado/router/info.rb', line 112 def connected_devices @connected_devices end |
#connection ⇒ String (readonly)
Get the currently active connection
46 47 48 |
# File 'lib/dovado/router/info.rb', line 46 def connection @connection end |
#date ⇒ Date (readonly)
Get the current date on the router
64 65 66 |
# File 'lib/dovado/router/info.rb', line 64 def date @date end |
#external_ip ⇒ IPAddr (readonly)
Get the external IP address of the router
58 59 60 |
# File 'lib/dovado/router/info.rb', line 58 def external_ip @external_ip end |
#gps_lat ⇒ Float (readonly)
Get the GPS latitude
82 83 84 |
# File 'lib/dovado/router/info.rb', line 82 def gps_lat @gps_lat end |
#gps_long ⇒ Float (readonly)
Get the GPS longitude
88 89 90 |
# File 'lib/dovado/router/info.rb', line 88 def gps_long @gps_long end |
#gps_type ⇒ String (readonly)
Get the GPS type
76 77 78 |
# File 'lib/dovado/router/info.rb', line 76 def gps_type @gps_type end |
#modem_status ⇒ String (readonly)
Get the current state of the connected modem
52 53 54 |
# File 'lib/dovado/router/info.rb', line 52 def modem_status @modem_status end |
#product_name ⇒ String (readonly)
Get the product name
19 20 21 |
# File 'lib/dovado/router/info.rb', line 19 def product_name @product_name end |
#signal_strength ⇒ Info::Signal (readonly)
Get the current signal strength information
26 27 28 |
# File 'lib/dovado/router/info.rb', line 26 def signal_strength @signal_strength end |
#sms ⇒ Sms (readonly)
Get the sms object
106 107 108 |
# File 'lib/dovado/router/info.rb', line 106 def sms @sms end |
#sunrise ⇒ Time (readonly)
Get the sunrise at the current location
94 95 96 |
# File 'lib/dovado/router/info.rb', line 94 def sunrise @sunrise end |
#sunset ⇒ Time (readonly)
Get sunset at the current location
100 101 102 |
# File 'lib/dovado/router/info.rb', line 100 def sunset @sunset end |
#time ⇒ Time (readonly)
Get the current time on the router
70 71 72 |
# File 'lib/dovado/router/info.rb', line 70 def time @time end |
#traffic_modem_rx ⇒ Integer (readonly)
Get the number of kilobytes read from the internet since last traffic counter reset.
40 41 42 |
# File 'lib/dovado/router/info.rb', line 40 def traffic_modem_rx @traffic_modem_rx end |
#traffic_modem_tx ⇒ Integer (readonly)
Get the number of kilobytes sent to the internet since last traffic counter reset.
33 34 35 |
# File 'lib/dovado/router/info.rb', line 33 def traffic_modem_tx @traffic_modem_tx end |
Instance Method Details
#[](key) ⇒ Object
Fetch an entry from the Dovado::Router::Info object.
185 186 187 |
# File 'lib/dovado/router/info.rb', line 185 def [](key) @data[key] end |
#create_from_string(data_string = nil) ⇒ Object
Create a new Dovado::Router::Info object from a String.
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/dovado/router/info.rb', line 130 def create_from_string(data_string=nil) unless Actor[:sms] Sms.supervise as: :sms, size: 1 end sms = Actor[:sms] data_array = data_string.split("\n") data_array.each do |data_entry| entry_array = data_entry.split('=') if entry_array.length == 2 key = entry_array[0].downcase val = entry_array[1] keysym = Utilities.name_to_sym(key) case key when 'traffic_modem_tx', 'traffic_modem_rx' @data[keysym] = val.strip.to_i when 'time', 'sunset', 'sunrise' @data[keysym] = Time.parse(val.strip) when 'date' @data[:date] = Date.parse(val.strip) when 'sms_unread' @data[:sms] = sms if @data[:sms].nil? @data[:sms].unread = val.strip.to_i when 'sms_total' @data[:sms] = sms if @data[:sms].nil? @data[:sms].total = val.strip.to_i when 'connected_devices' val = val.strip.split(',') @data[keysym] = val when 'gps_lat', 'gps_long' @data[keysym] = val.to_f when 'external_ip' @data[keysym] = IPAddr.new val.strip when 'signal_strength' match = val.strip.match(/(\d+)\W\%\W(\-?\d+)\WdBm\W\((\d\w)\)/) so = Info::Signal.new(strength: match[1], noise: match[2], network: match[3]) @data[keysym] = so else @data[keysym] = val.strip end end end touch! end |
#has_key?(key) ⇒ Boolean
Check if the Dovado::Router::Info object has a given key.
200 201 202 |
# File 'lib/dovado/router/info.rb', line 200 def has_key?(key) keys.member?(key) end |
#keys ⇒ Array<Symbol>
Fetch the list of entries in the Dovado::Router::Info object.
192 193 194 |
# File 'lib/dovado/router/info.rb', line 192 def keys @data.keys end |
#valid? ⇒ Boolean
Determine if this info object is valid.
177 178 179 180 |
# File 'lib/dovado/router/info.rb', line 177 def valid? return false if @last_update.nil? (@last_update + SecureRandom.random_number(9) + 1 <= Time.now.to_i) end |