simple-config 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8109bab781fdf4a5494770dfe9991d0105182d1b
4
- data.tar.gz: 42e44175a2172282ec114405797f9887fc6d98ec
3
+ metadata.gz: a97c9005bf678e8a459dcbe845bc31126def3a17
4
+ data.tar.gz: 3eb5ec3dd8ed8be990ca2780a0e2b1d7d5df90f2
5
5
  SHA512:
6
- metadata.gz: 7df19a144f1c934f52d292064a76efff1436a9e619149c9f5b542a8516b5e0be890ea4f83dba537e7cc9fcf42e8276e92acceb8e4eb50cf2123b2d688bbc2b55
7
- data.tar.gz: 96de7d1c081467272129c4f6cd787118866e210360a3c2ce2a2425aca9e986d92b7ae13e17a51854fbc74987bfd388037007c37c817fb540906a0cb6f9930c93
6
+ metadata.gz: c97cf4ae4f67be93506335b04b16956c25da41d84aca2a7327dec5d1b1cc59355837d78d92b55676a68f1d4d831a89e90dae99fad3875a8149cca9038d9ad9ab
7
+ data.tar.gz: 6d71f3c284926189843faadddd6ecbe2f5dfae726ab398d0059e17356c5a6ca5c9f44ded28319bb8acb74a4df549d63e5cc9e2178038bcbb23cff31f271c989d
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/lib/simple-config.rb CHANGED
@@ -5,24 +5,58 @@
5
5
  require 'line-tree'
6
6
 
7
7
  class SimpleConfig
8
+
9
+ attr_reader :to_h, :to_s
10
+
11
+ def initialize(x=nil)
12
+ m = {:String => :scan_to_h, :Hash => :scan_to_s}
13
+ method(m[x.class.to_s.to_sym]).call(x) if x
14
+ end
15
+
16
+ def parse(t=nil)
17
+ scan_to_h(t || @to_s)
18
+ end
19
+
20
+ def write(h=nil)
21
+ scan_to_s h || @to_h
22
+ end
23
+
24
+ private
8
25
 
9
- def self.parse(txt)
10
-
11
- raw_a = LineTree.new(txt.gsub(/^-*$/m,'')).to_a
26
+ def scan_to_h(txt)
27
+
28
+ raw_a = LineTree.new(txt.gsub(/(^-*$)|(#.*)/,'').strip).to_a
12
29
 
13
30
  a = raw_a.map do |line|
14
31
 
15
- s = line.is_a?(Array) ? line[0] : line
16
- value, name = s.split(':',2).reverse
17
- name ||= 'description'
18
-
19
- [name.to_sym, value.to_s.strip]
32
+ s = line.shift
33
+
34
+ if line.any? then
35
+ r = scan_to_h(line.join("\n"))
36
+ [s[/[^:]+/].to_sym, r]
37
+ else
38
+ value, name = s.split(':',2).reverse
39
+ name ||= 'description'
40
+
41
+ [name.to_sym, value.to_s.strip]
42
+ end
20
43
 
21
44
  end
22
45
 
23
- Hash[a]
24
- end
25
-
26
- def self.write(h) h.map{|key, value| "%s: %s" % [key, value]}.join("\n") end
46
+ @to_h = Hash[a]
47
+ end
48
+
49
+ def scan_to_s(h, indent='')
50
+
51
+ a = h.inject([]) do |r, x|
52
+ if x.last.is_a? Hash then
53
+ r << x.first.to_s + ":\n" + scan_to_s(x.last, ' ')
54
+ else
55
+ r << "%s%s: %s" % [indent, *x]
56
+ end
57
+ end
27
58
 
59
+ @to_s = a.join("\n")
60
+ end
61
+
28
62
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple-config
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -10,41 +10,49 @@ bindir: bin
10
10
  cert_chain:
11
11
  - |
12
12
  -----BEGIN CERTIFICATE-----
13
- MIIDRDCCAiygAwIBAgIBADANBgkqhkiG9w0BAQUFADBIMRIwEAYDVQQDDAlnZW1t
13
+ MIIDljCCAn6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBIMRIwEAYDVQQDDAlnZW1t
14
14
  YXN0ZXIxHjAcBgoJkiaJk/IsZAEZFg5qYW1lc3JvYmVydHNvbjESMBAGCgmSJomT
15
- 8ixkARkWAmV1MB4XDTEzMDIwNjI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2014-09-08 00:00:00.000000000 Z
33
35
  dependencies:
34
36
  - !ruby/object:Gem::Dependency
35
37
  name: line-tree
36
38
  requirement: !ruby/object:Gem::Requirement
37
39
  requirements:
38
- - - '>='
40
+ - - "~>"
39
41
  - !ruby/object:Gem::Version
40
- version: '0'
42
+ version: '0.3'
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 0.3.17
41
46
  type: :runtime
42
47
  prerelease: false
43
48
  version_requirements: !ruby/object:Gem::Requirement
44
49
  requirements:
45
- - - '>='
50
+ - - "~>"
51
+ - !ruby/object:Gem::Version
52
+ version: '0.3'
53
+ - - ">="
46
54
  - !ruby/object:Gem::Version
47
- version: '0'
55
+ version: 0.3.17
48
56
  description:
49
57
  email: james@r0bertson.co.uk
50
58
  executables: []
@@ -62,17 +70,17 @@ require_paths:
62
70
  - lib
63
71
  required_ruby_version: !ruby/object:Gem::Requirement
64
72
  requirements:
65
- - - '>='
73
+ - - ">="
66
74
  - !ruby/object:Gem::Version
67
- version: '0'
75
+ version: 2.1.2
68
76
  required_rubygems_version: !ruby/object:Gem::Requirement
69
77
  requirements:
70
- - - '>='
78
+ - - ">="
71
79
  - !ruby/object:Gem::Version
72
80
  version: '0'
73
81
  requirements: []
74
82
  rubyforge_project:
75
- rubygems_version: 2.0.0.rc.2
83
+ rubygems_version: 2.2.2
76
84
  signing_key:
77
85
  specification_version: 4
78
86
  summary: simple-config
metadata.gz.sig CHANGED
Binary file