Class: Yast::MapClass

Inherits:
Module
  • Object
show all
Defined in:
library/types/src/modules/Map.rb

Instance Method Summary collapse

Instance Method Details

#CheckKeys(m, keys) ⇒ Object

Check if a map contains all needed keys

Parameters:

  • m (Hash)

    map to be checked

  • keys (Array)

    needed keys

Returns:

  • true if map kontains all keys



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'library/types/src/modules/Map.rb', line 89

def CheckKeys(m, keys)
  m = deep_copy(m)
  keys = deep_copy(keys)
  return false if m.nil? || keys.nil?

  ret = true
  Builtins.foreach(keys) do |k|
    if k.nil? || !Builtins.haskey(m, k)
      Builtins.y2error("Missing key: %1", k)
      ret = false
    end
  end

  ret
end

#FromString(s) ⇒ Object

Convert string “var=val …” to map $[val:var, …]

Parameters:

  • s (String)

    string to be converted

Returns:

  • converted string



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'library/types/src/modules/Map.rb', line 122

def FromString(s)
  return {} if s.nil?

  ret = {}
  Builtins.foreach(Builtins.splitstring(s, " ")) do |vals|
    val = Builtins.splitstring(vals, "=")
    if Ops.less_than(Builtins.size(val), 1) ||
        Ops.get_string(val, 0, "") == ""
      next
    end
    key = Ops.get_string(val, 0, "")
    if Ops.greater_than(Builtins.size(val), 1)
      Ops.set(ret, key, Ops.get_string(val, 1, ""))
    else
      Ops.set(ret, key, "")
    end
  end
  deep_copy(ret)
end

#Keys(m) ⇒ Object

Return all keys from the map

Parameters:

  • m (Hash)

    the map

Returns:

  • a list of all keys from the map



44
45
46
47
48
# File 'library/types/src/modules/Map.rb', line 44

def Keys(m)
  m = deep_copy(m)
  return [] if m.nil? || m == {}
  Builtins.maplist(m) { |var, _val| var }
end

#KeysToLower(m) ⇒ Hash

Switch map keys to lower case

Parameters:

  • m (Hash{String => Object})

    input map

Returns:

  • (Hash)

    with keys converted to lower case



62
63
64
65
66
67
68
69
70
# File 'library/types/src/modules/Map.rb', line 62

def KeysToLower(m)
  m = deep_copy(m)
  newk = nil
  return {} if m.nil?
  Builtins.mapmap(m) do |k, v|
    newk = Builtins.tolower(k)
    { newk => v }
  end
end

#KeysToUpper(m) ⇒ Hash

Switch map keys to upper case

Parameters:

  • m (Hash{String => Object})

    input map

Returns:

  • (Hash)

    with keys converted to lower case



75
76
77
78
79
80
81
82
83
# File 'library/types/src/modules/Map.rb', line 75

def KeysToUpper(m)
  m = deep_copy(m)
  newk = nil
  return {} if m.nil?
  Builtins.mapmap(m) do |k, v|
    newk = Builtins.toupper(k)
    { newk => v }
  end
end

#mainObject



35
36
37
38
39
# File 'library/types/src/modules/Map.rb', line 35

def main
  textdomain "base"

  Yast.import "String"
end

#ToString(m) ⇒ Object

Convert options map $[var:val, …] to string “var=val …”

Parameters:

  • m (Hash)

    map to be converted

Returns:

  • converted map



108
109
110
111
112
113
114
115
116
117
# File 'library/types/src/modules/Map.rb', line 108

def ToString(m)
  m = deep_copy(m)
  return "" if m.nil?

  ret = ""
  Builtins.foreach(m) do |var, val|
    ret = Ops.add(ret, Builtins.sformat(" %1=%2", var, val))
  end
  String.CutBlanks(ret)
end

#Values(m) ⇒ Object

Return all values from the map

Parameters:

  • m (Hash)

    the map

Returns:

  • a list of all values from the map



53
54
55
56
57
# File 'library/types/src/modules/Map.rb', line 53

def Values(m)
  m = deep_copy(m)
  return [] if m.nil? || m == {}
  Builtins.maplist(m) { |_var, val| val }
end