module Asterisk::MessageHelper::ClassMethods

Public Instance Methods

parse_lines(str) click to toggle source
# File lib/asterisk/message_helper.rb, line 8
def parse_lines(str)
  hash = {}
  lines = str.gsub("\r", "").split("\n").select{|line| line.include?(":")}
  lines = lines.map{|line| [line.split(":")[0], line.split(":")[1..-1].join(":")]}
  lines = lines.map{|element| element.map{|e| e.strip}}
  lines = lines.flatten
  if lines.count > 0
    hash = Hash[*lines]
    hash.keys.each do |key|
      hash[(underscore(key).to_sym) || key] = hash.delete(key)
    end
  end
  hash
end
underscore(str) click to toggle source
# File lib/asterisk/message_helper.rb, line 23
def underscore(str)
  str.gsub(/::/, '/').
  gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
  gsub(/([a-z\d])([A-Z])/,'\1_\2').
  tr("-", "_").
  downcase
end