PoParser 0.1.1 → 0.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: 066ad9b453a020a745330142e832c8922e95a0da
4
- data.tar.gz: 8ce3ba60280751f10fb1b3a749d4ceb51247ab13
3
+ metadata.gz: c506fa6a54bff012c86629ea79bfdd53c414a43a
4
+ data.tar.gz: 44c9a383604e15653a4c9c196bf390c6d9f074b1
5
5
  SHA512:
6
- metadata.gz: 72264188d5c4bd28a4837cb29ba9cd5389618138ba3cd545c40fb563c0eaa2aff1ec159a8d302e63a0f7e8b2533070356e79e5290a19094071429ed9d7eea71c
7
- data.tar.gz: 02465743b232b2649580b9dc89a5b6757412ef3e71abc14129a0bec89a5a831859078a12a64cc9590af2550efe418e616ff6d7511d6150472307f7dd772fa6ee
6
+ metadata.gz: fbea1d35226cf6ffa877c0ac9c62c92e80510ef39e31597e2e32c27936e8379768e8c5850845e5d5dca774e70d28de7949667d5f5268355e927bff993662f9b8
7
+ data.tar.gz: 4b68497ef00ccf3c0f345dd00c10d35bd27b440ddf03846249291332e5ca9d077872e92bde26e536121abd0580f1b3fc56d8b357623263f4431c416ba61fea69
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## Version 0.2.0
2
+
3
+ * Some entries in PO files are started with "#~", these entries are just kept by program for later use and are not counted as active entries. `PoParser` now supports them. We won't count them in stats or show them in Tanslated or Untranslated entries. They're just there.
4
+
5
+ * Added size/length methods to `PO` class. It won't count cached entries(described above).
6
+
1
7
  ## Version 0.1.1
2
8
 
3
9
  * Fix bug of "str" and "to_str" on Messages
data/README.md CHANGED
@@ -36,6 +36,9 @@ The `parse` method returns a `PO` object which contains all `Entries`:
36
36
  # get all entries
37
37
  po.entries # or .all alias
38
38
 
39
+ # include cashed entries (started with "#~", these entries are just kept by program for later use and are not counted as active entries)
40
+ po.entries(true)
41
+
39
42
  # get all fuzzy entries
40
43
  po.fuzzy
41
44
 
@@ -80,6 +83,7 @@ refrence
80
83
  extracted_comment
81
84
  flag
82
85
  previous_untraslated_string
86
+ cached
83
87
  msgid
84
88
  msgid_plural
85
89
  msgstr
@@ -1,17 +1,18 @@
1
1
  module PoParser
2
2
  COMMENTS_LABELS = {
3
3
  :translator_comment => '#',
4
- :refrence => '#:',
5
4
  :extracted_comment => '#.',
5
+ :refrence => '#:',
6
6
  :flag => '#,',
7
7
  :previous_untraslated_string => '#|',
8
+ :cached => '#~'
8
9
  }
9
10
 
10
11
  ENTRIES_LABELS = {
12
+ :msgctxt => 'msgctxt',
11
13
  :msgid => 'msgid',
12
14
  :msgid_plural => 'msgid_plural',
13
- :msgstr => 'msgstr',
14
- :msgctxt => 'msgctxt'
15
+ :msgstr => 'msgstr'
15
16
  }
16
17
 
17
18
  LABELS = COMMENTS_LABELS.merge(ENTRIES_LABELS).keys
@@ -19,10 +19,19 @@ module PoParser
19
19
  self.class.send(:alias_method, :translate, :msgstr=)
20
20
  end
21
21
 
22
+ # If entry doesn't have any msgid, it's probably a cached entry that is
23
+ # kept by the program for later use. These entries will usually start with: #~
24
+ #
25
+ # @return [Boolean]
26
+ def cached?
27
+ !@cached.nil?
28
+ end
29
+
22
30
  # Checks if the entry is untraslated
23
31
  #
24
32
  # @return [Boolean]
25
33
  def untranslated?
34
+ return false if cached?
26
35
  @msgstr.nil? || @msgstr.to_s == ''
27
36
  end
28
37
  alias_method :incomplete? , :untranslated?
@@ -31,6 +40,7 @@ module PoParser
31
40
  #
32
41
  # @return [Boolean]
33
42
  def translated?
43
+ return false if cached?
34
44
  not untranslated?
35
45
  end
36
46
  alias_method :complete? , :translated?
@@ -46,6 +56,7 @@ module PoParser
46
56
  #
47
57
  # @return [Boolean]
48
58
  def fuzzy?
59
+ return false if cached?
49
60
  @flag.to_s == 'fuzzy'
50
61
  end
51
62
 
@@ -10,6 +10,7 @@ module PoParser
10
10
  refrence |
11
11
  extracted_comment | flag |
12
12
  previous_untraslated_string |
13
+ cached |
13
14
  translator_comment
14
15
  end
15
16
 
@@ -18,6 +19,7 @@ module PoParser
18
19
  rule(:refrence) { spaced('#:') >> comment_text_line.as(:refrence) }
19
20
  rule(:flag) { spaced('#,') >> comment_text_line.as(:flag) }
20
21
  rule(:previous_untraslated_string){ spaced('#|') >> comment_text_line.as(:previous_untraslated_string) }
22
+ rule(:cached) { spaced('#~') >> comment_text_line.as(:cached) }
21
23
 
22
24
  # Entries
23
25
  rule(:entries) do
data/lib/poparser/po.rb CHANGED
@@ -3,9 +3,7 @@ module PoParser
3
3
  #
4
4
  class Po
5
5
  include Enumerable
6
- attr_reader :entries
7
6
  attr_accessor :path
8
- alias_method :all, :entries
9
7
 
10
8
  def initialize(args = {})
11
9
  @entries = []
@@ -39,6 +37,21 @@ module PoParser
39
37
  end
40
38
  alias_method :<<, :add_entry
41
39
 
40
+ # Returns an array of all entries in po file
41
+ #
42
+ # @param include_cached [Boolean] Whether include cached entries or not
43
+ # @return [Array]
44
+ def entries(include_cached=false)
45
+ if include_cached
46
+ @entries
47
+ else
48
+ find_all do |entry|
49
+ !entry.cached?
50
+ end
51
+ end
52
+ end
53
+ alias_method :all, :entries
54
+
42
55
  # Finds all entries that are flaged as fuzzy
43
56
  #
44
57
  # @return [Array] an array of fuzzy entries
@@ -66,6 +79,14 @@ module PoParser
66
79
  end
67
80
  end
68
81
 
82
+ # Count of all entries without counting cached entries
83
+ #
84
+ # @return [String]
85
+ def size
86
+ entries.length
87
+ end
88
+ alias_method :length, :size
89
+
69
90
  # Shows statistics and status of the provided file in percentage.
70
91
  #
71
92
  # @return [Hash] a hash of translated, untranslated and fuzzy percentages
@@ -126,9 +147,8 @@ module PoParser
126
147
  #
127
148
  # @param [Integer] number of entries
128
149
  # @return [Float] percentage of the provided entries
129
- def percentage(size)
130
- total = @entries.size
131
- ((size.to_f / total) * 100).round(1)
150
+ def percentage(count)
151
+ ((count.to_f / self.size) * 100).round(1)
132
152
  end
133
153
  end
134
154
  end
@@ -1,3 +1,3 @@
1
1
  module PoParser
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
data/poparser.gemspec CHANGED
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
24
24
  # Development deps
25
25
  spec.add_development_dependency "bundler", "~> 1.5"
26
26
  spec.add_development_dependency "rake"
27
- spec.add_development_dependency "rspec", "~> 2.14"
27
+ spec.add_development_dependency "rspec", [">= 2.14", "< 2.99"]
28
28
  spec.add_development_dependency "guard-rspec"
29
29
  spec.add_development_dependency "pry-debugger"
30
30
  spec.add_development_dependency "awesome_print"
@@ -4,6 +4,7 @@ require 'spec_helper'
4
4
  describe PoParser::Entry do
5
5
  before(:each) do
6
6
  @entry = PoParser::Entry.new
7
+ @entry.msgid = 'some string'
7
8
  end
8
9
 
9
10
  let(:labels) do
@@ -82,4 +83,28 @@ describe PoParser::Entry do
82
83
  expect(@entry.to_s).to eq(result)
83
84
  end
84
85
  end
86
+
87
+ context 'Cached' do
88
+ before do
89
+ @entry = PoParser::Entry.new
90
+ @entry.cached = '#~ msgid "a cached entry"'
91
+ @entry.flag = 'Fuzzy'
92
+ end
93
+
94
+ it 'checks for chached entries' do
95
+ expect(@entry.cached?).to be_true
96
+ end
97
+
98
+ it 'shouldn be counted as untranslated' do
99
+ expect(@entry.untranslated?).to be_false
100
+ end
101
+
102
+ it 'shouldn be counted as translated' do
103
+ expect(@entry.translated?).to be_false
104
+ end
105
+
106
+ it 'shouldn\'t mark it as fuzzy' do
107
+ expect(@entry.fuzzy?).to be_false
108
+ end
109
+ end
85
110
  end
@@ -45,4 +45,11 @@ describe PoParser::Po do
45
45
  @po << [entry, entry2, entry3]
46
46
  ap @po.stats
47
47
  end
48
+
49
+ it 'shouldn\'t count cached entries' do
50
+ @po << entry
51
+ cached = { cached: 'sth', flag: 'Fuzzy' }
52
+ @po << cached
53
+ expect(@po.size).to eq(1)
54
+ end
48
55
  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: 0.1.1
4
+ version: 0.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: 2014-05-26 00:00:00.000000000 Z
11
+ date: 2014-06-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parslet
@@ -56,16 +56,22 @@ dependencies:
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '2.14'
62
+ - - "<"
63
+ - !ruby/object:Gem::Version
64
+ version: '2.99'
62
65
  type: :development
63
66
  prerelease: false
64
67
  version_requirements: !ruby/object:Gem::Requirement
65
68
  requirements:
66
- - - "~>"
69
+ - - ">="
67
70
  - !ruby/object:Gem::Version
68
71
  version: '2.14'
72
+ - - "<"
73
+ - !ruby/object:Gem::Version
74
+ version: '2.99'
69
75
  - !ruby/object:Gem::Dependency
70
76
  name: guard-rspec
71
77
  requirement: !ruby/object:Gem::Requirement
@@ -187,3 +193,4 @@ test_files:
187
193
  - spec/poparser/tokenizer_spec.rb
188
194
  - spec/poparser/transformer_spec.rb
189
195
  - spec/spec_helper.rb
196
+ has_rdoc: