class DEIS::Parse

Public Class Methods

JSON_to_set(json) click to toggle source
# File lib/rdeis/parse.rb, line 45
def self.JSON_to_set(json)
  cmd = ""
  json.each{|k,v| cmd += if v.to_s.length > 0 && v.to_s != "null" then "#{k}=\"#{v}\" " else "#{k} " end}
  cmd + " 2>&1"
end
JSON_to_unset(json) click to toggle source
# File lib/rdeis/parse.rb, line 51
def self.JSON_to_unset(json)
  cmd = ""
  json.each{|k,v| cmd += "#{k} "}
  cmd + " 2>&1"
end
first_proc() click to toggle source
# File lib/rdeis/parse.rb, line 69
def self.first_proc
  if (procs=DEIS::Parse.procs) && ! procs.nil? && procs.length > 0
    return "#{procs.first}=1"
  end
  nil
end
key(pair) click to toggle source

finds just the key from a string like KEY=VALUE

# File lib/rdeis/parse.rb, line 18
def self.key(pair)
  # start by assuming there might be no value or = symbol
  index = pair.length - 1
  index = pair.index("=") - 1 if ! pair.index("=").nil?
  # return the sub string
  pair[0..index]
end
list_array_to_var_string_array(data) click to toggle source

takes the array of [ [k, v], [k, v] ] and converts back to string K=V

# File lib/rdeis/parse.rb, line 39
def self.list_array_to_var_string_array(data)
  out = []
  data.each{|sub| out.push("#{sub.first}"+ if !sub[1].nil? then "=#{sub[1]}" else "" end) }
  out
end
procs() click to toggle source
# File lib/rdeis/parse.rb, line 57
def self.procs
  procs = []
  file = Dir.pwd+"/Procfile"
  if File.exists?(file)
    File.open(file, "r") {|f| f.read}.split("\n").each do |r|
      key = r.split(":").first
      procs.push(key)
    end
  end
  procs
end
value(pair) click to toggle source

finds just the value from a string like KEY=VALUE

# File lib/rdeis/parse.rb, line 27
def self.value(pair)
  #if theres no = then presume no value, just key, so default to nil
  index = pair.index("=")
  length = pair.length - 1
  if ! index.nil?
    pair[index+1..length]
  else
    nil
  end
end
var_array(vars) click to toggle source

vars is an array from the cli taking the form of: KEY=VALUE KEY1=V1 KEY2=V2 KEY1 KEY2

# File lib/rdeis/parse.rb, line 8
def self.var_array(vars)
  parsed = []
  if ! vars.nil? && vars.length > 0
    vars.each{ |pair| parsed.push ( {:k =>DEIS::Parse.key(pair), :v=>DEIS::Parse.value(pair) } ) }
  end
  # reverse so the last value of the key is used, then sort alpabetically, ignoring case
  parsed.reverse.uniq {|r| r[:k]}.sort{|a ,b | a[:k].downcase <=> b[:k].downcase}
end