Module: Pipe2me::ShellFormat
Constant Summary collapse
- PREFIX =
"PIPE2ME"
Instance Method Summary collapse
- #dump(obj, prefix = nil) ⇒ Object (also: #shell)
- #parse(data) ⇒ Object
- #read(path) ⇒ Object
- #write(path, data) ⇒ Object
Instance Method Details
#dump(obj, prefix = nil) ⇒ Object Also known as: shell
15 16 17 |
# File 'lib/pipe2me/ext/shell_format.rb', line 15 def dump(obj, prefix=nil) format_entries([], obj, prefix).join end |
#parse(data) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/pipe2me/ext/shell_format.rb', line 23 def parse(data) arrays = {} prefix_re = Regexp.compile(/^#{PREFIX.downcase}_/) data.lines.inject({}) do |hsh, line| key, value = line.split(/\s*=\s*/, 2) value.gsub!(/\s*$/, "") value = Integer(value) rescue value if key =~ /^(.*)_(\d+)$/ ary = arrays[$1] ||= [] ary[$2.to_i] = value key, value = $1, ary end hsh.update key.downcase.gsub(prefix_re, "").to_sym => value end end |
#read(path) ⇒ Object
11 12 13 |
# File 'lib/pipe2me/ext/shell_format.rb', line 11 def read(path) parse File.read(path) end |