PoParser 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 93ef3b40331e9ddb92b0e2e80cecdda8931c792d
4
- data.tar.gz: fb04bd5618a796539cc22654c35f819cfaa1ba95
3
+ metadata.gz: 066ad9b453a020a745330142e832c8922e95a0da
4
+ data.tar.gz: 8ce3ba60280751f10fb1b3a749d4ceb51247ab13
5
5
  SHA512:
6
- metadata.gz: 5db31ba15259828ab3fbd12f39ac9929ce3baa7244e2f51511ac9d46f31278c13aa40606af22c249e74d2ae3ccbc65b4996f9b0b0a62936dedaa2724260609ac
7
- data.tar.gz: 351db54dfc9b1e1b75945c13a1ecc4ad7da2cd7c6d4a0e659466f904f1b319c538081042dbb4b790ffd6ebbf580e9686fa066dd510eaad2870cfdacac5ff9c35
6
+ metadata.gz: 72264188d5c4bd28a4837cb29ba9cd5389618138ba3cd545c40fb563c0eaa2aff1ec159a8d302e63a0f7e8b2533070356e79e5290a19094071429ed9d7eea71c
7
+ data.tar.gz: 02465743b232b2649580b9dc89a5b6757412ef3e71abc14129a0bec89a5a831859078a12a64cc9590af2550efe418e616ff6d7511d6150472307f7dd772fa6ee
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## Version 0.1.1
2
+
3
+ * Fix bug of "str" and "to_str" on Messages
4
+ * Small refactoring
5
+
1
6
  ## Version 0.1.0
2
7
 
3
8
  * initial release
data/README.md CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  [![Build Status](https://travis-ci.org/arashm/PoParser.svg?branch=master)](https://travis-ci.org/arashm/PoParser)
4
4
  [![Coverage Status](https://img.shields.io/coveralls/arashm/PoParser.svg)](https://coveralls.io/r/arashm/PoParser)
5
+ [![Code Climate](https://codeclimate.com/github/arashm/PoParser.png)](https://codeclimate.com/github/arashm/PoParser)
5
6
 
6
7
  A Ruby PO file parser, editor and generator. PO files are translation files generated by GNU/Gettext tool. This GEM is compatible with [GNU PO file specification](https://www.gnu.org/software/gettext/manual/html_node/PO-Files.html). report misbehaviours and bugs, to the [issue tracker](https://github.com/arashm/PoParser/issues).
7
8
 
@@ -103,10 +104,10 @@ entry.plural?
103
104
  You can get or edit each of property of the `Entry`:
104
105
 
105
106
  ```ruby
106
- entry.msgid
107
+ entry.msgid.to_s
107
108
  #=> "This is an msgid that needs to get translated"
108
109
  entry.translate = "This entry is translated" # or msgstr= alias
109
- entry.msgstr
110
+ entry.msgstr.to_s
110
111
  #=> "This entry is translated"
111
112
  ```
112
113
 
@@ -1,27 +1,22 @@
1
1
  module PoParser
2
2
  class Entry
3
3
  # TODO: raise error if a label is not known
4
- def initialize(args= {})
4
+ def initialize(args = {})
5
5
  # Defining all instance variables to prevent warnings
6
6
  LABELS.each do |label|
7
7
  instance_variable_set "@#{label.to_s}".to_sym, nil
8
8
  end
9
9
 
10
10
  # Set passed arguments
11
- args.each do |type, string|
12
- if COMMENTS_LABELS.include? type
13
- instance_variable_set "@#{type.to_s}".to_sym, Comment.new(type, string)
14
- elsif ENTRIES_LABELS.include? type
15
- instance_variable_set "@#{type.to_s}".to_sym, Message.new(type, string)
16
- elsif type.to_s.match(/^msgstr\[[0-9]\]/)
17
- # If it's a plural msgstr
18
- @msgstr ||= []
19
- @msgstr << Message.new(type, string)
20
- end
11
+ args.each do |name, value|
12
+ set_instance_variable(name, value)
21
13
  end
22
14
 
23
- define_writer_methods
15
+ define_writer_methods(COMMENTS_LABELS, 'Comment')
16
+ define_writer_methods(ENTRIES_LABELS, 'Message')
24
17
  define_reader_methods
18
+
19
+ self.class.send(:alias_method, :translate, :msgstr=)
25
20
  end
26
21
 
27
22
  # Checks if the entry is untraslated
@@ -106,38 +101,35 @@ module PoParser
106
101
 
107
102
  private
108
103
 
109
- def define_writer_methods
110
- COMMENTS_LABELS.each do |type, mark|
111
- unless Entry.method_defined? "#{type}=".to_sym
112
- self.class.send(:define_method, "#{type}=".to_sym, lambda { |val|
113
- if instance_variable_get("@#{type}".to_sym).is_a? Comment
114
- comment = instance_variable_get "@#{type}".to_sym
115
- comment.type = type
116
- comment.str = val
117
- else
118
- instance_variable_set "@#{type}".to_sym, Comment.new(type, val)
119
- end
120
- instance_variable_get "@#{type}".to_sym
121
- })
122
- end
104
+ def set_instance_variable(name, value)
105
+ if COMMENTS_LABELS.include? name
106
+ instance_variable_set "@#{name.to_s}".to_sym, Comment.new(name, value)
107
+ elsif ENTRIES_LABELS.include? name
108
+ instance_variable_set "@#{name.to_s}".to_sym, Message.new(name, value)
109
+ elsif name.to_s.match(/^msgstr\[[0-9]\]/)
110
+ # If it's a plural msgstr
111
+ @msgstr ||= []
112
+ @msgstr << Message.new(name, value)
123
113
  end
114
+ end
124
115
 
125
- ENTRIES_LABELS.each do |type, mark|
116
+ def define_writer_methods(labels, object)
117
+ object = PoParser.const_get(object)
118
+ labels.each do |type, mark|
126
119
  unless Entry.method_defined? "#{type}=".to_sym
127
120
  self.class.send(:define_method, "#{type}=".to_sym, lambda { |val|
128
- if instance_variable_get("@#{type}".to_sym).is_a? Message
129
- message = instance_variable_get "@#{type}".to_sym
130
- message.type = type
131
- message.str = val
121
+ if instance_variable_get("@#{type}".to_sym).is_a? object
122
+ klass = instance_variable_get "@#{type}".to_sym
123
+ klass.type = type
124
+ klass.str = val
132
125
  else
133
- instance_variable_set "@#{type}".to_sym, Message.new(type, val)
126
+ instance_variable_set "@#{type}".to_sym, object.new(type, val)
134
127
  end
128
+ # return value
135
129
  instance_variable_get "@#{type}".to_sym
136
130
  })
137
131
  end
138
132
  end
139
-
140
- self.class.send(:alias_method, :translate, :msgstr=)
141
133
  end
142
134
 
143
135
  def define_reader_methods
@@ -11,7 +11,7 @@ module PoParser
11
11
  end
12
12
 
13
13
  def str
14
- @str.join
14
+ @str.is_a?(Array) ? @str.join : @str
15
15
  end
16
16
 
17
17
  def to_s(with_label = false)
@@ -30,7 +30,7 @@ module PoParser
30
30
  end
31
31
 
32
32
  def to_str
33
- @str.join
33
+ @str.is_a?(Array) ? @str.join : @str
34
34
  end
35
35
 
36
36
  private
@@ -1,3 +1,3 @@
1
1
  module PoParser
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  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.0
4
+ version: 0.1.1
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-25 00:00:00.000000000 Z
11
+ date: 2014-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parslet
@@ -148,7 +148,6 @@ files:
148
148
  - spec/poparser/test.po
149
149
  - spec/poparser/tokenizer_spec.rb
150
150
  - spec/poparser/transformer_spec.rb
151
- - spec/poparser/version_spec.rb
152
151
  - spec/spec_helper.rb
153
152
  homepage: http://github.com/arashm/poparser
154
153
  licenses:
@@ -187,5 +186,4 @@ test_files:
187
186
  - spec/poparser/test.po
188
187
  - spec/poparser/tokenizer_spec.rb
189
188
  - spec/poparser/transformer_spec.rb
190
- - spec/poparser/version_spec.rb
191
189
  - spec/spec_helper.rb
@@ -1,8 +0,0 @@
1
- require 'spec_helper'
2
-
3
- # Just as test to ensure that test suit is working correctly
4
- describe 'Version' do
5
- it 'shows the version correctly' do
6
- expect(PoParser::VERSION).to eq('0.0.1')
7
- end
8
- end