PoParser 3.1.1 → 3.2.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: 8018502bc7916464ebfb10b8c921f0f598f1df84
4
- data.tar.gz: 68ff2631dd26b8b483e15a4fa74973dbc4036a77
3
+ metadata.gz: 69d284ad281dcb8de53d79a3b92fb1336ee5ca7a
4
+ data.tar.gz: a33178e0caffc6d999b3eaf0707cc1c39aa9551f
5
5
  SHA512:
6
- metadata.gz: 5901356040586719f2f8e976902673bbc7e9c700fee986969779ef530f4abee445df61cd47648d3e952173f4d6d98abb77e4f683ee4549013f6ff6681c64ba19
7
- data.tar.gz: '02183e6e633d9218dd15c10318401470517e788e57808f12212a48b024d3985230b38024cfbe56ff8a75a0e5b340e6cfcfaf00899e7a4090c4ede6a6c93f09bf'
6
+ metadata.gz: 7b780472d5fa52e5b21fffdd65f876c4cf7434bea99b917b6d41baa6c4ba5898b7a6d6175015dd7f098b9e381618c5b8f625d6900b15c496b8ce27bb7da2159d
7
+ data.tar.gz: 4bbb2febfc6990f33c2788b6a96cdee43b1c8e394925b009a72cc477ad7b7467d88a6174c94201a56330b7dd5a7971d2dc8f681d6980d3d5275f48bf7aed767d
@@ -0,0 +1,35 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.3
3
+ Exclude:
4
+ - 'spec/**/*'
5
+ - 'db/**/*'
6
+ - 'app/views/**/*'
7
+ - 'config/**/*'
8
+ - 'bin/*'
9
+ - 'Rakefile'
10
+ - 'node_modules/**/*'
11
+
12
+ Bundler/OrderedGems:
13
+ Enabled: false
14
+
15
+ Metrics/BlockLength:
16
+ Exclude:
17
+ - 'lib/tasks/**/*'
18
+
19
+ Layout/MultilineMethodCallIndentation:
20
+ Enabled: true
21
+ EnforcedStyle: indented
22
+
23
+ Layout/AccessModifierIndentation:
24
+ EnforcedStyle: outdent
25
+
26
+ Layout/AlignParameters:
27
+ EnforcedStyle: with_fixed_indentation
28
+
29
+ Style/FrozenStringLiteralComment:
30
+ Enabled: false
31
+
32
+ Style/PercentLiteralDelimiters:
33
+ PreferredDelimiters:
34
+ '%i': '()'
35
+ '%w': '()'
@@ -2,7 +2,7 @@ bundler_args: --without development
2
2
  language: ruby
3
3
  sudo: false
4
4
  rvm:
5
- - 2.1.9
6
- - 2.2.5
7
- - 2.3.1
5
+ - 2.2.7
6
+ - 2.3.4
7
+ - 2.4.1
8
8
  script: bundle exec rspec spec
@@ -1,4 +1,10 @@
1
1
 
2
+ 3.2.0 / 2017-06-29
3
+ ==================
4
+
5
+ * Deprecate passing path to parse and introduce parse_file
6
+ * Drop ruby 2.1 since it is not supported any more
7
+
2
8
  3.1.1 / 2017-06-22
3
9
  ==================
4
10
 
data/Gemfile CHANGED
@@ -2,7 +2,7 @@ source 'https://rubygems.org'
2
2
 
3
3
  group :test do
4
4
  gem 'coveralls', :require => false
5
- gem 'rspec', '~> 3.5.0'
5
+ gem 'rspec', '~> 3.6.0'
6
6
  gem 'awesome_print'
7
7
  end
8
8
 
data/README.md CHANGED
@@ -27,9 +27,16 @@ Working with the GEM is pretty easy:
27
27
 
28
28
  ```ruby
29
29
  require 'poparser'
30
+
31
+ content = File.read('example.po')
32
+ po = PoParser.parse(content)
33
+ # => <PoParser::Po, Translated: 68.1% Untranslated: 20.4% Fuzzy: 11.5%>
34
+
35
+ # Or you could pass a file path:
36
+
30
37
  path = Pathname.new('example.po')
31
- po = PoParser.parse(path)
32
- => <PoParser::Po, Translated: 68.1% Untranslated: 20.4% Fuzzy: 11.5%>
38
+ po = PoParser.parse_file(path)
39
+ # => <PoParser::Po, Translated: 68.1% Untranslated: 20.4% Fuzzy: 11.5%>
33
40
  ```
34
41
 
35
42
  The `parse` method returns a `PO` object which contains all `Entries`:
@@ -13,8 +13,19 @@ require_relative 'poparser/version'
13
13
 
14
14
  module PoParser
15
15
  class << self
16
- def parse(path)
17
- Tokenizer.new.extract_entries(path)
16
+ def parse(payload)
17
+ if File.exist?(payload)
18
+ Kernel.warn 'DEPRICATION WARNING: `parse` only accepts content of a '\
19
+ 'PO file as a string and this behaviour will be removed on next '\
20
+ 'major release. Use `parse_file` instead.'
21
+ parse_file(payload)
22
+ else
23
+ Tokenizer.new.extract(payload)
24
+ end
25
+ end
26
+
27
+ def parse_file(path)
28
+ Tokenizer.new(true).extract(path)
18
29
  end
19
30
  end
20
31
  end
@@ -1,22 +1,33 @@
1
1
  module PoParser
2
2
  # Feed each block of PO file to Parser.
3
3
  class Tokenizer
4
- def initialize
4
+ def initialize(is_file = false)
5
5
  @po = Po.new
6
+ @is_file = is_file
6
7
  end
7
8
 
8
- def extract_entries(path)
9
- @po.path = path
10
- File.open(path, 'r:utf-8').each_line("\n\n") do |block|
11
- block.strip!
12
- @po << parse_block(block) if block != ''
9
+ def extract(payload)
10
+ if @is_file
11
+ @po.path = payload
12
+ payload = File.read(payload, mode: 'r:utf-8')
13
13
  end
14
- @po
14
+
15
+ extract_entries(payload)
15
16
  end
16
17
 
17
18
  private
19
+
18
20
  def parse_block(block)
19
- hash = SimplePoParser.parse_message(block)
21
+ SimplePoParser.parse_message(block)
22
+ end
23
+
24
+ def extract_entries(payload)
25
+ payload.split("\n\n").each do |block|
26
+ block.strip!
27
+ @po << parse_block(block) if block != ''
28
+ end
29
+
30
+ @po
20
31
  end
21
32
  end
22
33
  end
@@ -1,3 +1,3 @@
1
1
  module PoParser
2
- VERSION = "3.1.1"
2
+ VERSION = "3.2.0"
3
3
  end
@@ -132,8 +132,8 @@ describe PoParser::Entry do
132
132
  end
133
133
 
134
134
  it 'should further parse the obsolete content' do
135
- path = Pathname.new('spec/poparser/fixtures/complex_obsolete.po').realpath
136
- @po = PoParser::Tokenizer.new.extract_entries(path)
135
+ file = File.read('spec/poparser/fixtures/complex_obsolete.po')
136
+ @po = PoParser::Tokenizer.new.extract(file)
137
137
  obsolete_entry = @po.obsolete.first
138
138
  expect(obsolete_entry.obsolete?).to be_truthy
139
139
  expect(obsolete_entry.msgctxt.value).to eq('Context')
@@ -11,7 +11,7 @@ describe PoParser::Po do
11
11
  }
12
12
  end
13
13
 
14
- before(:each) do
14
+ before do
15
15
  @po = PoParser::Po.new
16
16
  end
17
17
 
@@ -68,7 +68,7 @@ describe PoParser::Po do
68
68
  context 'search' do
69
69
  before do
70
70
  path = Pathname.new('spec/poparser/fixtures/test.po').realpath
71
- @po = PoParser::Tokenizer.new.extract_entries(path)
71
+ @po = PoParser::Tokenizer.new(true).extract(path)
72
72
  end
73
73
 
74
74
  it 'raises error if label is not valid' do
@@ -87,7 +87,7 @@ describe PoParser::Po do
87
87
  context 'Header' do
88
88
  before do
89
89
  path = Pathname.new('spec/poparser/fixtures/header.po').realpath
90
- @po = PoParser::Tokenizer.new.extract_entries(path)
90
+ @po = PoParser::Tokenizer.new(true).extract(path)
91
91
  end
92
92
 
93
93
  it 'should respond to header' do
@@ -119,9 +119,10 @@ describe PoParser::Po do
119
119
 
120
120
  it 'throws error if there\'re two header string' do
121
121
  path = Pathname.new('spec/poparser/fixtures/header_error.po').realpath
122
+
122
123
  expect{
123
- @po = PoParser::Tokenizer.new.extract_entries(path)
124
- }.to raise_error(RuntimeError, "Duplicate entry, header was already instantiated")
124
+ PoParser::Tokenizer.new(true).extract(path)
125
+ }.to raise_error(RuntimeError, "Duplicate entry, header was already instantiated")
125
126
  end
126
127
  end
127
128
 
@@ -3,6 +3,7 @@ require "spec_helper"
3
3
 
4
4
  describe PoParser do
5
5
  let(:po_file) { Pathname.new('spec/poparser/fixtures/tokenizer.po').realpath }
6
+ let(:po_file_content) { File.read('spec/poparser/fixtures/tokenizer.po') }
6
7
  let(:header_fixture) { Pathname.new('spec/poparser/fixtures/header.po').realpath }
7
8
  let(:multiline_fixture) { Pathname.new('spec/poparser/fixtures/multiline.po').realpath }
8
9
  let(:plural_fixture) { Pathname.new('spec/poparser/fixtures/plural.po').realpath }
@@ -12,6 +13,20 @@ describe PoParser do
12
13
  expect(PoParser.parse(po_file)).to be_a_kind_of PoParser::Po
13
14
  end
14
15
 
16
+ it 'should print deprecation warning when passing file to parse' do
17
+ expect(Kernel).to receive(:warn).with(
18
+ 'DEPRICATION WARNING: `parse` only accepts content of a PO '\
19
+ 'file as a string and this behaviour will be removed on next major '\
20
+ 'release. Use `parse_file` instead.'
21
+ ).once
22
+
23
+ PoParser.parse(po_file)
24
+ end
25
+
26
+ it 'parses a payload' do
27
+ expect(PoParser.parse(po_file_content)).to be_a_kind_of PoParser::Po
28
+ end
29
+
15
30
  it 'correclty parses header fixture' do
16
31
  entry = PoParser::Entry.new(
17
32
  {
@@ -132,5 +147,4 @@ describe PoParser do
132
147
  allow_any_instance_of(PoParser::Header).to receive(:puts)
133
148
  expect(PoParser.parse(test_fixture).to_s).to eq(expected_result.to_s)
134
149
  end
135
-
136
150
  end
@@ -2,20 +2,18 @@
2
2
  require "spec_helper.rb"
3
3
 
4
4
  describe PoParser::Tokenizer do
5
- let(:token) { PoParser::Tokenizer.new }
5
+ let(:token) { PoParser::Tokenizer.new(true) }
6
6
  let(:po_file){ Pathname.new('spec/poparser/fixtures/tokenizer.po').realpath }
7
7
  let(:po_file_empty_line){ Pathname.new('spec/poparser/fixtures/tokenizer_empty_line.po').realpath }
8
8
  let(:result) { [{:reference=>"templates:105", :msgid=>"Afrikaans", :msgstr=>"آفریقایی"}, {:flag=>"fuzzy", :msgid=>"Afrikaans", :msgstr=>"آفریقایی" }] }
9
9
 
10
10
  it 'should be able to extracts entries' do
11
- expect(
12
- token.extract_entries(po_file).to_h
13
- ).to eq(result)
11
+ expect(token.extract(po_file).to_h).to eq(result)
14
12
  end
15
13
 
16
14
  it 'should gracefully handle empty lines at the beginning' do
17
15
  expect(
18
- token.extract_entries(po_file_empty_line).to_h
16
+ token.extract(po_file_empty_line).to_h
19
17
  ).to eq(result)
20
18
  end
21
19
  end
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: 3.1.1
4
+ version: 3.2.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: 2017-06-22 00:00:00.000000000 Z
11
+ date: 2017-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: simple_po_parser
@@ -62,6 +62,7 @@ extra_rdoc_files: []
62
62
  files:
63
63
  - ".gitignore"
64
64
  - ".rspec"
65
+ - ".rubocop.yml"
65
66
  - ".travis.yml"
66
67
  - CHANGELOG.md
67
68
  - Gemfile