Class: Termy::Info
- Inherits:
-
Object
- Object
- Termy::Info
- Defined in:
- lib/termy/info.rb
Instance Attribute Summary collapse
-
#info ⇒ Object
readonly
Returns the value of attribute info.
Instance Method Summary collapse
-
#initialize ⇒ Info
constructor
A new instance of Info.
- #show(user_info_keys) ⇒ Object
- #show_all ⇒ Object
Constructor Details
#initialize ⇒ Info
Returns a new instance of Info.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/termy/info.rb', line 7 def initialize sf = Termy::SystemFacts.new @info = { "system" => { "architecture" => sf.arch, "boot_id" => sf.boot_id, "date" => sf.date, "domainname" => sf.domainname, "hostname" => sf.hostname, "network" => sf.network, "file_systems" => sf.file_systems, "os_release" => sf.os_release, "kernel" => sf.kernel, "machine_id" => sf.machine_id, } } end |
Instance Attribute Details
#info ⇒ Object (readonly)
Returns the value of attribute info.
6 7 8 |
# File 'lib/termy/info.rb', line 6 def info @info end |
Instance Method Details
#show(user_info_keys) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/termy/info.rb', line 29 def show(user_info_keys) keys = user_info_keys.first.split(":") info_keys = @info.keys info = @info data = nil begin keys.each do |key| data = info[key] info = data.is_a?(String) ? { key => data } : data raise key if info.nil? end rescue => e puts "InvalidKeyError: key \"#{e}\" not found" exit end puts JSON.pretty_generate(info) end |
#show_all ⇒ Object
25 26 27 |
# File 'lib/termy/info.rb', line 25 def show_all puts JSON.pretty_generate(@info) end |