class NativePackageInstaller::OSRelease

Public Class Methods

new() click to toggle source
# File lib/native-package-installer/os-release.rb, line 20
def initialize
  parse
end

Public Instance Methods

[](key) click to toggle source
# File lib/native-package-installer/os-release.rb, line 28
def [](key)
  @variables[key]
end
each(&block) click to toggle source
# File lib/native-package-installer/os-release.rb, line 24
def each(&block)
  @variables.each(&block)
end
id() click to toggle source
# File lib/native-package-installer/os-release.rb, line 32
def id
  self["ID"]
end
id_like() click to toggle source
# File lib/native-package-installer/os-release.rb, line 36
def id_like
  (self["ID_LIKE"] || "").split(/ /)
end
version() click to toggle source
# File lib/native-package-installer/os-release.rb, line 40
def version
  self["VERSION"]
end

Private Instance Methods

parse() click to toggle source
# File lib/native-package-installer/os-release.rb, line 45
def parse
  @variables = {}
  path = "/etc/os-release"
  return unless File.exist?(path)
  File.foreach(path) do |line|
    key, value = line.strip.split("=", 2)
    next if value.nil?
    if value.start_with?("\"") and value.end_with?("\"")
      value = value[1..-2]
    end
    @variables[key] = value
  end
end