class String

Public Instance Methods

anvlesc() click to toggle source
# File lib/anvl/core_ext/ruby/string.rb, line 20
def anvlesc
  self.gsub(/%/, "%25").gsub(/\n/, "%0A").gsub(/\r/, "%0D")
end
anvlunesc() click to toggle source
# File lib/anvl/core_ext/ruby/string.rb, line 24
def anvlunesc
  self.gsub(/%25/, "%").gsub(/%0A/, "\n").gsub(/%0D/, "\r").gsub(/%3A/, ":")
end
from_anvl() click to toggle source
# File lib/anvl/core_ext/ruby/string.rb, line 2
def from_anvl
  hsh = self.split("\n").reduce({}) do |sum, line|
    if line.start_with?("#")
      # ignore
    elsif line.include?(":")
      k, v = line.split(":", 2)
      sum[k.to_s.strip.anvlunesc] = v.to_s.strip.sub(/\A['"](.*)['"]\z/, '\\1').anvlunesc
    elsif line.strip.present? && line.start_with?(" ")
      sum[sum.keys.last] += " " + line.strip
    end

    sum
  end

  # use string or symbol for keys
  HashWithIndifferentAccess.new(hsh)
end