module AppConfig::Processor

Public Instance Methods

process(data, type) click to toggle source

Process data value for the format

# File lib/app-config/processor.rb, line 33
def process(data, type)
  raise InvalidType, 'Type is invalid!' unless FORMATS.include?(type)
  send("process_#{type}".to_sym, data.to_s)
end
process_array(value) click to toggle source

Process array of strings

# File lib/app-config/processor.rb, line 9
def process_array(value)
  value.split("\n").map { |s| s.to_s.strip }.compact.select { |s| !s.empty? }
end
process_boolean(value) click to toggle source

Parse boolean string

# File lib/app-config/processor.rb, line 14
def process_boolean(value)
  ['true', 'on', 'yes', 'y', '1'].include?(value.to_s.downcase)
end
process_hash(value) click to toggle source

Parse hash string value should be in the following format: “keyname: value, key2: value2”

# File lib/app-config/processor.rb, line 21
def process_hash(value)
  result = {}
  unless value.empty?
    value.split(",").each do |s|
      k,v = s.split(':').compact.map { |i| i.to_s.strip }
      result[k] = v.to_s
    end
  end
  result
end
process_string(value) click to toggle source

Process string value

# File lib/app-config/processor.rb, line 4
def process_string(value)
  value.strip
end