Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/anvl/core_ext/ruby/string.rb
Instance Method Summary collapse
Instance Method Details
#anvlesc ⇒ Object
20 21 22 |
# File 'lib/anvl/core_ext/ruby/string.rb', line 20 def anvlesc self.gsub(/%/, "%25").gsub(/\n/, "%0A").gsub(/\r/, "%0D") end |
#anvlunesc ⇒ Object
24 25 26 |
# 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 ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# 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 |