PoParser 1.1.0 → 2.0.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: 954ba00cb0682d03951ff75fc7de053d515a621b
4
- data.tar.gz: 40d00d176527e9c4ff109cd44dd3c46c16674a42
3
+ metadata.gz: 0e320991c1d0d99631e3e9f69479d8b4a4e32e75
4
+ data.tar.gz: a22450eeb90828fa9396ab9e3ae4a066286282ac
5
5
  SHA512:
6
- metadata.gz: 8b1635f9d67863a2ffe25c0051b3d772d3ae595f8600fe190d152524441a4f44354b1b95929ca2b47ea46526bb80a52646919796c67610d822bdc85261bf6ffe
7
- data.tar.gz: 1bfa4f0d0d4df93cba148577e3b803113c627758c26e1cee69de0f823d8fbf0b82dfdd912ce7c98c7b9866dbc08a1cc6a2768f2fc4e685e7415b7aafd2d6362f
6
+ metadata.gz: b7244529dfffea1b170cc164581de87a9098cf3a0f4ca981de3c3a0a2a4a5fba222a8b32cd766cfee7ead2a750d6d19740718a8829a9590bde737b6b4b2d74f2
7
+ data.tar.gz: 5ab25bb5cfbc95cfe0bb0a131bdebae1b71d16eabf26c4b0adc378611244ed85ae4020ef04d991120b3a7c5c1af8c1606fd28240d0c4144dfcd41b9ffbc5b189
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+
2
+ 2.0.0 / 2016-12-22
3
+ ==================
4
+
5
+ * `Comment#to_s` now returns string instead of array (backward incompatible)
6
+ * Parser won't choke on cases where there are spaces before eol
7
+
1
8
  1.1.0 / 2016-12-07
2
9
  ==================
3
10
 
@@ -1,32 +1,32 @@
1
1
  module PoParser
2
2
  class Comment
3
- attr_accessor :type, :str
3
+ attr_accessor :type, :value
4
4
 
5
- def initialize(type, str)
5
+ def initialize(type, value)
6
6
  @type = type
7
- @str = str
7
+ @value = value
8
8
  end
9
9
 
10
10
  def to_s(with_label = false)
11
- return @str unless with_label
12
- if @str.is_a? Array
11
+ return to_str unless with_label
12
+ if @value.is_a? Array
13
13
  string = []
14
- @str.each do |str|
14
+ @value.each do |str|
15
15
  string << "#{COMMENTS_LABELS[@type]} #{str}\n".gsub(/[^\S\n]+$/, '')
16
16
  end
17
17
  return string.join
18
18
  else
19
19
  # removes the space but not newline at the end
20
- "#{COMMENTS_LABELS[@type]} #{@str}\n".gsub(/[^\S\n]+$/, '')
20
+ "#{COMMENTS_LABELS[@type]} #{@value}\n".gsub(/[^\S\n]+$/, '')
21
21
  end
22
22
  end
23
23
 
24
24
  def to_str
25
- @str
25
+ @value.is_a?(Array) ? @value.join : @value
26
26
  end
27
27
 
28
28
  def inspect
29
- @str
29
+ @value
30
30
  end
31
31
  end
32
32
  end
@@ -146,7 +146,7 @@ module PoParser
146
146
  if instance_variable_get("@#{type}".to_sym).is_a? object
147
147
  klass = instance_variable_get "@#{type}".to_sym
148
148
  klass.type = type
149
- klass.str = val
149
+ klass.value = val
150
150
  else
151
151
  instance_variable_set "@#{type}".to_sym, object.new(type, val)
152
152
  end
@@ -7,7 +7,7 @@ module PoParser
7
7
 
8
8
  def initialize(entry)
9
9
  @entry = entry
10
- @comments = entry.translator_comment.to_s
10
+ @comments = entry.translator_comment.value
11
11
  @original_configs = convert_msgstr_to_hash(entry.msgstr)
12
12
 
13
13
  HEADER_LABELS.each do |k, v|
@@ -46,7 +46,7 @@ module PoParser
46
46
 
47
47
  private
48
48
  def convert_msgstr_to_hash(msgstr)
49
- options_array = msgstr.to_s.map do |options|
49
+ options_array = msgstr.value.map do |options|
50
50
  options.split(':', 2).each do |k|
51
51
  k.strip!
52
52
  k.chomp!
@@ -70,4 +70,3 @@ module PoParser
70
70
  end
71
71
  end
72
72
  end
73
-
@@ -1,46 +1,45 @@
1
1
  module PoParser
2
2
  class Message
3
- attr_accessor :type
4
- attr_writer :str
3
+ attr_accessor :type, :value
5
4
 
6
- def initialize(type, str)
5
+ def initialize(type, value)
7
6
  @type = type
8
- @str = str
7
+ @value = value
9
8
 
10
9
  remove_empty_line
11
10
  end
12
11
 
13
12
  def str
14
- @str.is_a?(Array) ? @str.join : @str
13
+ @value.is_a?(Array) ? @value.join : @value
15
14
  end
16
15
 
17
16
  def to_s(with_label = false)
18
- return @str unless with_label
19
- if @str.is_a? Array
17
+ return to_str unless with_label
18
+ if @value.is_a? Array
20
19
  remove_empty_line
21
20
  # multiline messages should be started with an empty line
22
21
  lines = ["#{label} \"\"\n"]
23
- @str.each do |str|
22
+ @value.each do |str|
24
23
  lines << "\"#{str}\"\n"
25
24
  end
26
25
  return lines.join
27
26
  else
28
- "#{label} \"#{@str}\"\n"
27
+ "#{label} \"#{@value}\"\n"
29
28
  end
30
29
  end
31
30
 
32
31
  def to_str
33
- @str.is_a?(Array) ? @str.join : @str
32
+ @value.is_a?(Array) ? @value.join : @value
34
33
  end
35
34
 
36
35
  def inspect
37
- @str
36
+ @value
38
37
  end
39
38
 
40
39
  private
41
40
  def remove_empty_line
42
- if @str.is_a? Array
43
- @str.shift if @str.first == ''
41
+ if @value.is_a? Array
42
+ @value.shift if @value.first == ''
44
43
  end
45
44
  end
46
45
 
@@ -46,7 +46,7 @@ module PoParser
46
46
  rule(:character) { escaped | text }
47
47
  rule(:text) { any }
48
48
  rule(:escaped) { str('\\') >> any }
49
- rule(:msg_line_end){ str('"') >> eol }
49
+ rule(:msg_line_end){ str('"') >> space? >> eol }
50
50
 
51
51
  rule(:comment_text_line) do
52
52
  (eol.absent? >> character).repeat.maybe.as(:text) >> eol
@@ -1,3 +1,3 @@
1
1
  module PoParser
2
- VERSION = "1.1.0"
2
+ VERSION = "2.0.0"
3
3
  end
@@ -1,6 +1,6 @@
1
1
  msgid ""
2
2
  "first"
3
3
  "second"
4
- msgstr ""
4
+ msgstr ""
5
5
  "aval"
6
6
  "dovom"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: PoParser
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arash Mousavi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-07 00:00:00.000000000 Z
11
+ date: 2016-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parslet