simple_po_parser 1.1.0 → 1.1.1

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: 10a107f2a74fa7cf6902d58c15f466705a52ef0c
4
- data.tar.gz: 63369a5ede32deb4846c07a9206cc1a09cc4989c
3
+ metadata.gz: 74fd13b4d65428c06cebf73f052271c53fe2403b
4
+ data.tar.gz: eca6c142f4c5272f06e66ea9fcc88ce68261cbbc
5
5
  SHA512:
6
- metadata.gz: f905113fc6890089e63110702d752b90cf3d2d678399d42f3ddd3d088fdcab787caf453d6a07fa07b0cc9b947a5b90aebc025ee33c20025a9174f6a829183424
7
- data.tar.gz: 26591d6acbf9c279ddbd7986ba4d320bc6c525858740dd6d7fc86f87971fe795d16d95524c297703c24190140f372ebf994b2df81602180d8dbfadc177ff100c
6
+ metadata.gz: 4b41b0f49b24ec840e044471c675662057bff8fb76474e8bf7480b3d1cf44c10cee5c98e3bae9e1336ff49e09d9bcdf5780b2bc0e82498210ed761902c8fd369
7
+ data.tar.gz: e1ec0a70f6dbdfb4ad53bc84fb4457c7e61f5e5d4c508f58a8efbc505d19692c647e747d87250f343bbcfbb52884e47f5c8740bb356174b9fe75f031d45a1798
data/Gemfile CHANGED
@@ -4,6 +4,7 @@ group :test do
4
4
  gem 'coveralls', :require => false
5
5
  gem 'rspec', '~> 3.5.0'
6
6
  gem 'awesome_print'
7
+ gem 'ruby-prof'
7
8
  end
8
9
 
9
10
  gemspec
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- simple_po_parser (1.0.0)
4
+ simple_po_parser (1.1.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -32,6 +32,7 @@ GEM
32
32
  diff-lcs (>= 1.2.0, < 2.0)
33
33
  rspec-support (~> 3.5.0)
34
34
  rspec-support (3.5.0)
35
+ ruby-prof (0.16.2)
35
36
  simplecov (0.12.0)
36
37
  docile (~> 1.1.0)
37
38
  json (>= 1.8, < 3)
@@ -52,7 +53,8 @@ DEPENDENCIES
52
53
  geminabox-release (= 0.2.1)
53
54
  rake
54
55
  rspec (~> 3.5.0)
56
+ ruby-prof
55
57
  simple_po_parser!
56
58
 
57
59
  BUNDLED WITH
58
- 1.13.6
60
+ 1.14.6
data/README.md CHANGED
@@ -6,11 +6,21 @@
6
6
 
7
7
  This is a simple PO file to ruby hash parser, which complies with [GNU PO file specification](https://www.gnu.org/software/gettext/manual/html_node/PO-Files.html). Tested with the msgcat (GNU gettext-tools) 0.18.3 tool.
8
8
 
9
- ## Hash format
9
+ ## Usage
10
+
11
+ The parser can be used in two ways:
12
+
13
+ ```ruby
14
+ SimplePoParser.parse(file_path) # parses a PO file and returns array of hashes
15
+
16
+ SimplePoParser.parse_message(message) # parses a single PO message and returns a hash
17
+ ```
18
+
19
+ ### Hash format
10
20
 
11
21
  A PO message is parsed into a hash with meaningful keys for each type of line.
12
- The values are strings, if only one line of such content was parsed,
13
- otherthise it's an array of strings. Each string is
22
+ The values are strings if only one line of such content was parsed,
23
+ otherwise it's an array of strings. Each string is
14
24
  representing one line of content in the PO file.
15
25
 
16
26
  ```ruby
@@ -30,6 +40,6 @@ A PO message is parsed into a hash with meaningful keys for each type of line.
30
40
  }
31
41
  ```
32
42
 
33
- ### License
43
+ ## License
34
44
 
35
45
  License: [MIT](LICENSE.txt) - Copyright (c) 2017 Dennis-Florian Herr @Experteer GmbH
data/Rakefile CHANGED
@@ -54,8 +54,8 @@ namespace :parser do
54
54
  desc "Show ruby-prof profiler for spec/fixtures/complex_entry.po"
55
55
  task "profile_parser" do
56
56
  require 'ruby-prof'
57
- RubyProf.start
58
57
  po_message = File.read(File.expand_path("spec/simple_po_parser/fixtures/complex_entry.po", __dir__))
58
+ RubyProf.start
59
59
  SimplePoParser.parse_message(po_message)
60
60
  result = RubyProf.stop
61
61
 
@@ -164,7 +164,7 @@ module SimplePoParser
164
164
  end
165
165
  end
166
166
 
167
- # matches the msgstr singular line
167
+ # parses the msgstr singular line
168
168
  #
169
169
  # msgstr is required in singular translations
170
170
  def msgstr
@@ -184,7 +184,13 @@ module SimplePoParser
184
184
  end
185
185
  end
186
186
 
187
-
187
+ # parses the msgstr plural lines
188
+ #
189
+ # msgstr plural lines are used when there is msgid_plural.
190
+ # They have the format msgstr[N] where N is incremental number starting from zero representing
191
+ # the plural number as specified in the headers "Plural-Forms" entry. Most languages, like the
192
+ # English language only have two plural forms (singular and plural),
193
+ # but there are languages with more plurals
188
194
  def msgstr_plural(num = 0)
189
195
  begin
190
196
  msgstr_key = @scanner.scan(/msgstr\[\d\]/) # matches 'msgstr[0]' to 'msgstr[9]'
@@ -207,6 +213,12 @@ module SimplePoParser
207
213
  end
208
214
  end
209
215
 
216
+ # parses previous comments, which provide additional information on fuzzy matching
217
+ #
218
+ # previous comments are:
219
+ # * #| msgctxt
220
+ # * #| msgid
221
+ # * #| msgid_plural
210
222
  def previous_comments
211
223
  begin
212
224
  # next part must be msgctxt, msgid or msgid_plural
@@ -234,6 +246,7 @@ module SimplePoParser
234
246
  end
235
247
  end
236
248
 
249
+ # parses the multiline messages of the previous comment lines
237
250
  def previous_multiline(key)
238
251
  begin
239
252
  # scan multilines until no further multiline is hit
@@ -249,6 +262,10 @@ module SimplePoParser
249
262
  end
250
263
  end
251
264
 
265
+ # parses a multiline message
266
+ #
267
+ # multiline messages are indicated by an empty content as first line and the next line
268
+ # starting with the double quote character
252
269
  def message_multiline(key)
253
270
  begin
254
271
  skip_whitespace
@@ -290,7 +307,8 @@ module SimplePoParser
290
307
  end
291
308
  end
292
309
 
293
- # used to parse all obsolete lines. An obsolete message may only contain obsolete entries
310
+ # parses all obsolete lines.
311
+ # An obsolete message may only contain obsolete lines
294
312
  def obsoletes
295
313
  if @scanner.scan(/#~/)
296
314
  skip_whitespace
@@ -333,6 +351,8 @@ module SimplePoParser
333
351
  end
334
352
 
335
353
  # returns true if the scanner is at beginning of next line or end of string
354
+ #
355
+ # @return [Boolean] true if scanner at beginning of line or eos
336
356
  def end_of_line
337
357
  @scanner.scan(/\n/)
338
358
  @scanner.eos? || @scanner.bol?
@@ -351,7 +371,5 @@ module SimplePoParser
351
371
  @result[key] = text
352
372
  end
353
373
  end
354
-
355
374
  end
356
-
357
375
  end
@@ -1,3 +1,3 @@
1
1
  module SimplePoParser
2
- VERSION = "1.1.0"
2
+ VERSION = "1.1.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_po_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dennis-Florian Herr
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-03 00:00:00.000000000 Z
11
+ date: 2017-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler