kvparser 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/kvparser.rb +30 -0
- metadata +45 -0
data/lib/kvparser.rb
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
module KeyValueParser
|
|
2
|
+
extend self
|
|
3
|
+
|
|
4
|
+
def parse(str, options = {})
|
|
5
|
+
result = {}
|
|
6
|
+
options[:sep_char] ||= '='
|
|
7
|
+
options[:line_char] ||= "\n"
|
|
8
|
+
options[:trim_values] = true unless options.include?(:trim_values)
|
|
9
|
+
options[:comment_char] ||= '#'
|
|
10
|
+
|
|
11
|
+
str.gsub!("\r\n", "\n") if (options[:line_char] == "\n")
|
|
12
|
+
|
|
13
|
+
str.each_line(options[:line_char]) { | line |
|
|
14
|
+
line = line.gsub!(/^#{options[:line_char]}*/, '').gsub(/#{options[:line_char]}*$/, '')
|
|
15
|
+
unless line.strip.empty?
|
|
16
|
+
key, value = line.split(options[:sep_char], 2)
|
|
17
|
+
unless value.nil?
|
|
18
|
+
key.strip!
|
|
19
|
+
if (options[:comment_char] == '') || (!key.start_with?(options[:comment_char]))
|
|
20
|
+
key.gsub!(' ', '_')
|
|
21
|
+
value.strip! if options[:trim_values]
|
|
22
|
+
result[key.to_sym] = value
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
}
|
|
27
|
+
return result
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: kvparser
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
prerelease:
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- Taco Jan Osinga
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2013-03-27 00:00:00.000000000 Z
|
|
13
|
+
dependencies: []
|
|
14
|
+
description: A simple KeyValueParser, ideal for reading string resources
|
|
15
|
+
email: info@osingasoftware.nl
|
|
16
|
+
executables: []
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- lib/kvparser.rb
|
|
21
|
+
homepage: http://rubygems.org/gems/kvparser
|
|
22
|
+
licenses: []
|
|
23
|
+
post_install_message:
|
|
24
|
+
rdoc_options: []
|
|
25
|
+
require_paths:
|
|
26
|
+
- lib
|
|
27
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
28
|
+
none: false
|
|
29
|
+
requirements:
|
|
30
|
+
- - ! '>='
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '0'
|
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
34
|
+
none: false
|
|
35
|
+
requirements:
|
|
36
|
+
- - ! '>='
|
|
37
|
+
- !ruby/object:Gem::Version
|
|
38
|
+
version: '0'
|
|
39
|
+
requirements: []
|
|
40
|
+
rubyforge_project:
|
|
41
|
+
rubygems_version: 1.8.25
|
|
42
|
+
signing_key:
|
|
43
|
+
specification_version: 3
|
|
44
|
+
summary: KeyValueParser
|
|
45
|
+
test_files: []
|