Class: Yast::MapClass
- Inherits:
-
Module
- Object
- Module
- Yast::MapClass
- Defined in:
- library/types/src/modules/Map.rb
Instance Method Summary collapse
-
#CheckKeys(map, keys) ⇒ Object
Check if a map contains all needed keys.
-
#FromString(string) ⇒ Object
Convert string "var=val ..." to map $[val:var, ...].
-
#Keys(map) ⇒ Object
Return all keys from the map.
-
#KeysToLower(map) ⇒ Hash
Switch map keys to lower case.
-
#KeysToUpper(map) ⇒ Hash
Switch map keys to upper case.
- #main ⇒ Object
-
#ToString(map) ⇒ Object
Convert options map $[var:val, ...] to string "var=val ...".
-
#Values(map) ⇒ Object
Return all values from the map.
Instance Method Details
#CheckKeys(map, keys) ⇒ Object
Check if a map contains all needed keys
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'library/types/src/modules/Map.rb', line 91 def CheckKeys(map, keys) map = deep_copy(map) keys = deep_copy(keys) return false if map.nil? || keys.nil? ret = true Builtins.foreach(keys) do |k| if k.nil? || !Builtins.haskey(map, k) Builtins.y2error("Missing key: %1", k) ret = false end end ret end |
#FromString(string) ⇒ Object
Convert string "var=val ..." to map $[val:var, ...]
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'library/types/src/modules/Map.rb', line 124 def FromString(string) return {} if string.nil? ret = {} Builtins.foreach(Builtins.splitstring(string, " ")) 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(map) ⇒ Object
Return all keys from the map
42 43 44 45 46 47 |
# File 'library/types/src/modules/Map.rb', line 42 def Keys(map) map = deep_copy(map) return [] if map.nil? || map == {} Builtins.maplist(map) { |var, _val| var } end |
#KeysToLower(map) ⇒ Hash
Switch map keys to lower case
62 63 64 65 66 67 68 69 70 71 |
# File 'library/types/src/modules/Map.rb', line 62 def KeysToLower(map) map = deep_copy(map) newk = nil return {} if map.nil? Builtins.mapmap(map) do |k, v| newk = Builtins.tolower(k) { newk => v } end end |
#KeysToUpper(map) ⇒ Hash
Switch map keys to upper case
76 77 78 79 80 81 82 83 84 85 |
# File 'library/types/src/modules/Map.rb', line 76 def KeysToUpper(map) map = deep_copy(map) newk = nil return {} if map.nil? Builtins.mapmap(map) do |k, v| newk = Builtins.toupper(k) { newk => v } end end |
#main ⇒ Object
33 34 35 36 37 |
# File 'library/types/src/modules/Map.rb', line 33 def main textdomain "base" Yast.import "String" end |
#ToString(map) ⇒ Object
Convert options map $[var:val, ...] to string "var=val ..."
110 111 112 113 114 115 116 117 118 119 |
# File 'library/types/src/modules/Map.rb', line 110 def ToString(map) map = deep_copy(map) return "" if map.nil? ret = "" Builtins.foreach(map) do |var, val| ret = Ops.add(ret, Builtins.sformat(" %1=%2", var, val)) end String.CutBlanks(ret) end |
#Values(map) ⇒ Object
Return all values from the map
52 53 54 55 56 57 |
# File 'library/types/src/modules/Map.rb', line 52 def Values(map) map = deep_copy(map) return [] if map.nil? || map == {} Builtins.maplist(map) { |_var, val| val } end |