iniparse 1.3.3 → 1.4.0

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: 495078e17e0358686da8bc6e375483281140bc39
4
- data.tar.gz: fdee56564996ea5af6d7ba0dd51cf7952135264f
3
+ metadata.gz: df89c5288250ac2060dc5fff2d55a8f58ed150ec
4
+ data.tar.gz: fb378ab6a528d5c718a39b24b1429872a6724a25
5
5
  SHA512:
6
- metadata.gz: 15751da5f0bea27de9b682a25602c21036136d6b87abf2b3786f4cbd1076d146943ac000214f61986449b48ec0ac6842f3e24b7d40137f9a5855f91b16181df3
7
- data.tar.gz: 087fe62daf3a872cf7f13edccdab3a72743a1c2a1474c7137f2dc927e0496ff10548b5453e47571c0e2d18bcebe4210e58eed82f9c0ec7833d668ddb44b92c08
6
+ metadata.gz: aa5111d419e946cfdab3bc81dd811461594e94e44d2664b891d3271b514d65f6c0475daceef40d56bcf9232808d14481b3e240f0bf0eb63c822fdf0aaed60387
7
+ data.tar.gz: c6f7dd510ad5beba9120abae324c1ebc7429ae827b046c96a145b8d7c790329c80d2d91d20829c292753aa14ce5faf95c9500554410a188c7dd9024e8b07df7a
data/Rakefile CHANGED
@@ -51,7 +51,7 @@ task :release => :build do
51
51
  puts "You must be on the master branch to release!"
52
52
  exit!
53
53
  end
54
- # sh "git commit --allow-empty -a -m 'Release #{version}'"
54
+ sh "git commit --allow-empty -a -m 'Release #{version}'"
55
55
  sh "git tag v#{version}"
56
56
  sh "git push origin master"
57
57
  sh "git push origin v#{version}"
@@ -12,8 +12,8 @@ Gem::Specification.new do |s|
12
12
  ## If your rubyforge_project name is different, then edit it and comment out
13
13
  ## the sub! line in the Rakefile
14
14
  s.name = 'iniparse'
15
- s.version = '1.3.3'
16
- s.date = '2014-10-30'
15
+ s.version = '1.4.0'
16
+ s.date = '2015-04-06'
17
17
  s.rubyforge_project = 'iniparse'
18
18
 
19
19
  s.summary = 'A pure Ruby library for parsing INI documents.'
@@ -7,7 +7,7 @@ require File.join(dir, 'lines')
7
7
  require File.join(dir, 'parser')
8
8
 
9
9
  module IniParse
10
- VERSION = '1.3.3'
10
+ VERSION = '1.4.0'
11
11
 
12
12
  # A base class for IniParse errors.
13
13
  class IniParseError < StandardError; end
@@ -36,7 +36,7 @@ module IniParse
36
36
  # IniParse::Document
37
37
  #
38
38
  def parse(source)
39
- IniParse::Parser.new(source).parse
39
+ IniParse::Parser.new(source.gsub("\\\n", '')).parse
40
40
  end
41
41
 
42
42
  # Opens the file at +path+, reads and parses it's contents.
@@ -51,6 +51,24 @@ module IniParse
51
51
 
52
52
  alias_method :to_s, :to_ini
53
53
 
54
+ # Returns a has representation of the INI with multi-line options
55
+ # as an array
56
+ def to_hash
57
+ result = {}
58
+ @lines.entries.each do |section|
59
+ result[section.key] ||= {}
60
+ section.entries.each do |option|
61
+ opts = Array(option)
62
+ val = opts.map { |o| o.respond_to?(:value) ? o.value : o }
63
+ val = val.size > 1 ? val : val.first
64
+ result[section.key][opts.first.key] = val
65
+ end
66
+ end
67
+ result
68
+ end
69
+
70
+ alias_method :to_h, :to_hash
71
+
54
72
  # A human-readable version of the document, for debugging.
55
73
  def inspect
56
74
  sections = @lines.select { |l| l.is_a?(IniParse::Lines::Section) }
@@ -21,16 +21,14 @@ module IniParse
21
21
  # Returns this line as a string as it would be represented in an INI
22
22
  # document.
23
23
  def to_ini
24
- ini = line_contents
25
- ini = @indent + ini if @indent
26
-
27
- if has_comment?
28
- ini += ' ' if ini =~ /\S/ # not blank
29
- ini = ini.ljust(@comment_offset)
30
- ini += comment
31
- end
32
-
33
- ini
24
+ [*line_contents].map { |ini|
25
+ if has_comment?
26
+ ini += ' ' if ini =~ /\S/ # not blank
27
+ ini = ini.ljust(@comment_offset)
28
+ ini += comment
29
+ end
30
+ @indent + ini
31
+ }.join "\n"
34
32
  end
35
33
 
36
34
  # Returns the contents for this line.
@@ -48,6 +46,17 @@ module IniParse
48
46
  def blank?
49
47
  false
50
48
  end
49
+
50
+ # Returns the options used to create the line
51
+ def options
52
+ {
53
+ comment: @comment,
54
+ comment_sep: @comment_sep,
55
+ comment_prefix: @comment_prefix,
56
+ comment_offset: @comment_offset,
57
+ indent: @indent
58
+ }
59
+ end
51
60
  end
52
61
 
53
62
  # Represents a section header in an INI document. Section headers consist
@@ -93,13 +102,13 @@ module IniParse
93
102
  coll = lines.to_a
94
103
 
95
104
  if coll.any?
96
- super + $/ + coll.to_a.map do |line|
105
+ [*super,coll.to_a.map do |line|
97
106
  if line.kind_of?(Array)
98
107
  line.map { |dup_line| dup_line.to_ini }.join($/)
99
108
  else
100
109
  line.to_ini
101
110
  end
102
- end.join($/)
111
+ end].join($/)
103
112
  else
104
113
  super
105
114
  end
@@ -132,7 +141,14 @@ module IniParse
132
141
  # new option to be considered a duplicate, use +add_option+ instead.
133
142
  #
134
143
  def []=(key, value)
135
- @lines[key.to_s] = IniParse::Lines::Option.new(key.to_s, value)
144
+ line = @lines[key.to_s]
145
+ opts = {}
146
+ if line.kind_of?(Array)
147
+ opts = line.first.options
148
+ elsif line.respond_to? :options
149
+ opts = line.options
150
+ end
151
+ @lines[key.to_s] = IniParse::Lines::Option.new(key.to_s, value, opts)
136
152
  end
137
153
 
138
154
  # Returns the value of an option identified by +key+.
@@ -271,8 +287,14 @@ module IniParse
271
287
  private
272
288
  #######
273
289
 
290
+ # returns an array to support multiple lines or a single one at once
291
+ # because of options key duplication
274
292
  def line_contents
275
- '%s = %s' % [key, value]
293
+ if value.kind_of?(Array)
294
+ value.map { |v, i| "#{key} = #{v}" }
295
+ else
296
+ "#{key} = #{value}"
297
+ end
276
298
  end
277
299
  end
278
300
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iniparse
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.3
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anthony Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-30 00:00:00.000000000 Z
11
+ date: 2015-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec