Module: Accessibility::SystemInfo
Overview
Interface for collecting some simple information about the system. This information may be useful as diagnostic output when running tests, or if you simply need to find the hostname of the machine so it can be passed to another process to initiate a connection.
This module extends itself, so all methods are available on the module and you will want to use the module as a utility module.
Instance Method Summary collapse
-
#addresses ⇒ Array<String>
All IP addresses the system has interfaces for.
-
#battery_charge_level ⇒ Float
(also: #battery_level)
Returns the charge percentage of the battery (if present).
-
#battery_life_estimate ⇒ Fixnum
Return an estimate on the number of minutes until the battery is drained.
-
#battery_state ⇒ Symbol
Return the current state of the battery.
-
#hostname ⇒ Array<String>
The first, and likely common, name the system responds to.
-
#hostnames ⇒ Array<String>
All hostnames that the system responds to.
-
#ipv4_addresses ⇒ Array<String>
All IPv4 addresses the system has interfaces for.
-
#ipv6_addresses ⇒ Array<String>
All IPv6 addresses the system has interfaces for.
-
#model ⇒ String
System model string.
-
#name ⇒ String
The name the machine uses for Bonjour.
-
#num_active_processors ⇒ Fixnum
(also: #number_of_active_processors)
Number of CPUs the system current has enabled.
-
#num_processors ⇒ Fixnum
(also: #number_of_processors)
Total number of CPUs the system could use.
-
#osx_version ⇒ String
OS X version string.
-
#total_ram ⇒ Fixnum
(also: #ram)
Total amount of memory for the system, in bytes.
-
#uptime ⇒ Float
System uptime, in seconds.
Instance Method Details
#addresses ⇒ Array<String>
All IP addresses the system has interfaces for
62 63 64 |
# File 'lib/accessibility/system_info.rb', line 62 def addresses NSHost.currentHost.addresses end |
#battery_charge_level ⇒ Float Also known as: battery_level
Returns the charge percentage of the battery (if present)
A special value of -1.0
is returned if you have no battery.
203 204 205 |
# File 'lib/accessibility/system_info.rb', line 203 def battery_charge_level Battery.level end |
#battery_life_estimate ⇒ Fixnum
Return an estimate on the number of minutes until the battery is drained
A special value of 0
indicates that the battery is not discharging.
You should really only call this after you know that the battery is
discharging by calling #battery_state and having :discharging
returned.
A special value of -1
is returned when the estimate is in flux and
cannot be accurately estimated.
228 229 230 |
# File 'lib/accessibility/system_info.rb', line 228 def battery_life_estimate Battery.time_to_empty end |
#battery_state ⇒ Symbol
Return the current state of the battery
184 185 186 |
# File 'lib/accessibility/system_info.rb', line 184 def battery_state Battery.state end |
#hostname ⇒ Array<String>
The first, and likely common, name the system responds to
49 50 51 |
# File 'lib/accessibility/system_info.rb', line 49 def hostname hostnames.first end |
#hostnames ⇒ Array<String>
All hostnames that the system responds to
37 38 39 |
# File 'lib/accessibility/system_info.rb', line 37 def hostnames NSHost.currentHost.names end |
#ipv4_addresses ⇒ Array<String>
All IPv4 addresses the system has interfaces for
75 76 77 |
# File 'lib/accessibility/system_info.rb', line 75 def ipv4_addresses addresses.select { |address| address.match /\./ } end |
#ipv6_addresses ⇒ Array<String>
All IPv6 addresses the system has interfaces for
88 89 90 |
# File 'lib/accessibility/system_info.rb', line 88 def ipv6_addresses addresses.select { |address| address.match /:/ } end |
#model ⇒ String
System model string
100 101 102 |
# File 'lib/accessibility/system_info.rb', line 100 def model @model ||= `sysctl hw.model`.split.last.chomp end |
#name ⇒ String
The name the machine uses for Bonjour
24 25 26 |
# File 'lib/accessibility/system_info.rb', line 24 def name NSHost.currentHost.localizedName end |
#num_active_processors ⇒ Fixnum Also known as: number_of_active_processors
Number of CPUs the system current has enabled
151 152 153 |
# File 'lib/accessibility/system_info.rb', line 151 def num_active_processors NSProcessInfo.processInfo.activeProcessorCount end |
#num_processors ⇒ Fixnum Also known as: number_of_processors
Total number of CPUs the system could use
May not be the same as #num_active_processors.
138 139 140 |
# File 'lib/accessibility/system_info.rb', line 138 def num_processors NSProcessInfo.processInfo.processorCount end |
#osx_version ⇒ String
OS X version string
112 113 114 |
# File 'lib/accessibility/system_info.rb', line 112 def osx_version NSProcessInfo.processInfo. end |
#total_ram ⇒ Fixnum Also known as: ram
Total amount of memory for the system, in bytes
164 165 166 |
# File 'lib/accessibility/system_info.rb', line 164 def total_ram NSProcessInfo.processInfo.physicalMemory end |
#uptime ⇒ Float
System uptime, in seconds
124 125 126 |
# File 'lib/accessibility/system_info.rb', line 124 def uptime NSProcessInfo.processInfo.systemUptime end |