Sha256: 7832df1bfadd8787f67b71c1dd630c51bc0c2a4877bb7ae2dd52dc2e76696b78

Contents?: true

Size: 1.48 KB

Versions: 9

Compression:

Stored size: 1.48 KB

Contents

module KPM
  module SystemProxy
    module OsInformation
      class << self

        def fetch
          os_information  = nil
          if OS.windows?
            os_information  = fetch_windows
          elsif OS.linux?
            os_information  = fetch_linux
          elsif OS.mac?
            os_information  = fetch_mac
          end

          os_information
        end

        def get_labels
          labels = [{:label => :os_detail},
                    {:label => :value}]
          labels
        end

        private
          def fetch_linux
            os_data = `lsb_release -a 2>&1`

            if os_data.nil? || os_data.include?('lsb_release: not found')
              os_data = `cat /etc/issue 2>&1`
              os_data = 'Description:'+os_data.gsub('\n \l','')
            end

            os = get_hash(os_data)
            os
          end

          def fetch_mac
            os_data = `sw_vers`
            os = get_hash(os_data)
            os
          end

          def fetch_windows
            os_data = `systeminfo | findstr /C:"OS"`
            os = get_hash(os_data)
            os
          end

          def get_hash(data)
            os = Hash.new

            unless data.nil?
              data.split("\n").each do |info|
                infos = info.split(':')
                os[infos[0].to_s.strip] = {:os_detail => infos[0].to_s.strip, :value => infos[1].to_s.strip}
              end
            end

            os
          end

      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
kpm-0.7.2 lib/kpm/system_helpers/os_information.rb
kpm-0.7.1 lib/kpm/system_helpers/os_information.rb
kpm-0.7.0 lib/kpm/system_helpers/os_information.rb
kpm-0.6.5 lib/kpm/system_helpers/os_information.rb
kpm-0.6.4 lib/kpm/system_helpers/os_information.rb
kpm-0.6.3 lib/kpm/system_helpers/os_information.rb
kpm-0.6.2 lib/kpm/system_helpers/os_information.rb
kpm-0.6.1 lib/kpm/system_helpers/os_information.rb
kpm-0.6.0 lib/kpm/system_helpers/os_information.rb