xliffer 1.0.2 → 1.0.3

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: f2c02d93b1d9d6bab91e7f11acc68b009627647a
4
- data.tar.gz: 47287acd5be0ca4262a2bdcfaf6e10f48ec0ce70
3
+ metadata.gz: 3c29a80258b1cfcf31ced1de9bd964236291e258
4
+ data.tar.gz: acea02334221f81e6aaf5f269991ca321ffc8261
5
5
  SHA512:
6
- metadata.gz: f877905bc87525bd2771c8bd9f68ebfdf893147e73813ee8999f0c73636456d38e51aadca814874adf22bb5a34708600642e9e02e511ad4173f9cad28ea6040c
7
- data.tar.gz: 3679c4fd443dd9c93788f758f55b09988ea31c252ff3a3dc75ad0e88676b59ab95575221ffca152fe95b3333cea82e9304bf19cb435bb164a59b7b848c1f21a4
6
+ metadata.gz: dab58fa8560313c44d35fd14c1959038c88668672331ca9617ed2039d008307ce97de5416fe1400557f6a608df78e9696f11d5ddab724793eeaf252daaa70ab4
7
+ data.tar.gz: 4b5567873006d671eaefb09e5a81efda623585754a21c67fed484068bd78ac6b03809435ce90ebacb66f93cb95e493b76b0e10e08bf3206443fa58da33d8947a
@@ -0,0 +1,13 @@
1
+ # This will acuse `expect {` from being bad style
2
+ Style/BlockDelimiters:
3
+ Enabled: false
4
+
5
+ # We support ruby 1.8
6
+ Style/HashSyntax:
7
+ Enabled: false
8
+
9
+ Style/Documentation:
10
+ Enabled: false
11
+
12
+ Metrics/ModuleLength:
13
+ Max: 250
@@ -1,5 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
+ - "2.3.0"
3
4
  - "2.2.2"
4
5
  - "2.1.6"
5
6
  - "2.0.0"
data/Gemfile CHANGED
@@ -1,11 +1,11 @@
1
- source "http://rubygems.org"
1
+ source 'http://rubygems.org'
2
2
 
3
3
  gem 'nokogiri', '~> 1.5.10'
4
4
  gem 'equivalent-xml'
5
5
 
6
6
  group :test do
7
7
  unless RUBY_VERSION.match(/\A1\.8/)
8
- gem "codeclimate-test-reporter", :require => false
8
+ gem 'codeclimate-test-reporter', :require => false
9
9
  end
10
10
  end
11
11
 
@@ -1,3 +1,3 @@
1
1
  module XLIFFer
2
- VERSION = "1.0.2"
2
+ VERSION = '1.0.3'
3
3
  end
@@ -8,7 +8,7 @@ module XLIFFer
8
8
  text = case xliff
9
9
  when ::IO then xliff.read
10
10
  when ::String then xliff
11
- else fail ArgumentError, "Expects an IO or String"
11
+ else fail ArgumentError, 'Expects an IO or String'
12
12
  end
13
13
 
14
14
  parse(text)
@@ -19,12 +19,13 @@ module XLIFFer
19
19
  end
20
20
 
21
21
  private
22
+
22
23
  def parse(text)
23
24
  @xml = Nokogiri::XML(text)
24
25
 
25
26
  @xml.remove_namespaces!
26
27
  root = @xml.xpath('/xliff')
27
- raise FormatError, "Not a XLIFF file" unless root.any?
28
+ fail FormatError, 'Not a XLIFF file' unless root.any?
28
29
 
29
30
  @version = get_version(root)
30
31
  @files = parse_files(root)
@@ -36,12 +37,11 @@ module XLIFFer
36
37
  end
37
38
 
38
39
  def parse_files(root)
39
- root.xpath('//file').map{|f| File.new(f)}
40
+ root.xpath('//file').map { |f| File.new(f) }
40
41
  end
41
42
 
42
43
  def self.xml_element?(xml)
43
- xml.kind_of? Nokogiri::XML::Element
44
+ xml.is_a? Nokogiri::XML::Element
44
45
  end
45
-
46
46
  end
47
47
  end
@@ -1,4 +1,3 @@
1
- require 'xliffer/xliff'
2
1
  require 'nokogiri'
3
2
 
4
3
  module XLIFFer
@@ -7,16 +6,16 @@ module XLIFFer
7
6
  attr_reader :source_language, :target_language, :original, :strings
8
7
  alias_method :file_name, :original
9
8
  def initialize(xml)
10
- unless XLIFF::xml_element?(xml) and file?(xml)
11
- raise ArgumentError, "can't create a File without a file subtree"
9
+ unless XLIFF.xml_element?(xml) && file?(xml)
10
+ fail ArgumentError, "can't create a File without a file subtree"
12
11
  end
13
12
 
14
13
  @xml = xml
15
14
 
16
- @original = @xml.attr("original")
17
- @source_language = @xml.attr("source-language")
18
- @target_language = @xml.attr("target-language")
19
- @strings = @xml.xpath('.//trans-unit').map{|tu| String.new(tu) }
15
+ @original = @xml.attr('original')
16
+ @source_language = @xml.attr('source-language')
17
+ @target_language = @xml.attr('target-language')
18
+ @strings = @xml.xpath('.//trans-unit').map { |tu| String.new(tu) }
20
19
  end
21
20
 
22
21
  def [](id)
@@ -36,10 +35,11 @@ module XLIFFer
36
35
  @target_language = val
37
36
  @xml['target-language'] = val
38
37
  end
38
+
39
39
  private
40
40
 
41
41
  def file?(xml)
42
- xml.name.downcase == "file"
42
+ xml.name.downcase == 'file'
43
43
  end
44
44
  end
45
45
  end
@@ -3,15 +3,16 @@ module XLIFFer
3
3
  class String
4
4
  attr_reader :id, :source, :target, :note
5
5
  def initialize(trans_unit_xml)
6
- unless XLIFF::xml_element?(trans_unit_xml) and trans_unit?(trans_unit_xml)
7
- raise ArgumentError, "can't create a String without a trans-unit subtree"
6
+ unless XLIFF.xml_element?(trans_unit_xml) && trans_unit?(trans_unit_xml)
7
+ error_message = "can't create a String without a trans-unit subtree"
8
+ fail ArgumentError, error_message
8
9
  end
9
10
 
10
11
  @xml = trans_unit_xml
11
12
  @id = @xml.attr('id')
12
- @source = get_source
13
- @target = get_target
14
- @note = get_note
13
+ @source = find_source
14
+ @target = find_target
15
+ @note = find_note
15
16
  end
16
17
 
17
18
  def target=(val)
@@ -29,19 +30,25 @@ module XLIFFer
29
30
  private
30
31
 
31
32
  def trans_unit?(xml)
32
- xml.name.downcase == "trans-unit"
33
+ xml.name.downcase == 'trans-unit'
33
34
  end
34
35
 
35
- def get_source
36
- sources = @xml.xpath("./source")
37
- raise MultipleElement, "Should have only one source tag" if sources.size > 1
38
- raise NoElement, "Should have one source tag" unless sources.size == 1
36
+ def find_source
37
+ sources = @xml.xpath('./source')
38
+ error_message = 'Should have only one source tag'
39
+ fail MultipleElement, error_message if sources.size > 1
40
+
41
+ error_message = 'Should have one source tag'
42
+ fail NoElement, error_message unless sources.size == 1
39
43
  sources.first.text
40
44
  end
41
45
 
42
- def get_target
43
- targets = @xml.xpath("./target")
44
- raise MultipleElement, "Should have only one target tag" if targets.size > 1
46
+ def find_target
47
+ targets = @xml.xpath('./target')
48
+
49
+ error_message = 'Should have only one target tag'
50
+ fail MultipleElement, error_message if targets.size > 1
51
+
45
52
  if targets.empty?
46
53
  targets << Nokogiri::XML::Node.new('target', @xml)
47
54
  @xml.add_child(targets.first)
@@ -49,9 +56,10 @@ module XLIFFer
49
56
  targets.first.text
50
57
  end
51
58
 
52
- def get_note
53
- notes = @xml.xpath("./note")
54
- raise MultipleElement, "Should have only one target tag" if notes.size > 1
59
+ def find_note
60
+ notes = @xml.xpath('./note')
61
+ error_message = 'Should have only one target tag'
62
+ fail MultipleElement, error_message if notes.size > 1
55
63
  notes.first ? notes.first.text : ''
56
64
  end
57
65
  end
@@ -1,5 +1,5 @@
1
1
  unless RUBY_VERSION.match(/\A1\.8/)
2
- require "codeclimate-test-reporter"
2
+ require 'codeclimate-test-reporter'
3
3
  require 'simplecov'
4
4
  CodeClimate::TestReporter.start
5
5
  SimpleCov.start
@@ -3,78 +3,78 @@ require 'nokogiri'
3
3
 
4
4
  module XLIFFer
5
5
  describe XLIFF::File do
6
- describe "#new" do
7
- it "is created with a nokogiri file node" do
8
- file_node = Nokogiri::XML.parse("<file></file>").xpath("/file").first
6
+ describe '#new' do
7
+ it 'is created with a nokogiri file node' do
8
+ file_node = Nokogiri::XML.parse('<file></file>').xpath('/file').first
9
9
  expect(XLIFF::File.new(file_node)).to be
10
10
  end
11
11
 
12
12
  it "can't be created with a string" do
13
- expect{XLIFF::File.new("<file></file>")}.to raise_error ArgumentError
13
+ expect { XLIFF::File.new('<file></file>') }.to raise_error ArgumentError
14
14
  end
15
15
 
16
16
  it "can't be created with a node that is not a file node" do
17
- file_node = Nokogiri::XML.parse("<xliff><file></file></xliff>").xpath("/xliff").first
18
- expect{XLIFF::File.new(file_node)}.to raise_error ArgumentError
17
+ xml = Nokogiri::XML.parse('<xliff><file></file></xliff>')
18
+ file_node = xml.xpath('/xliff').first
19
+ expect { XLIFF::File.new(file_node) }.to raise_error ArgumentError
19
20
  end
20
21
  end
21
22
 
22
- describe "#original" do
23
- it "is nil if not defined" do
24
- file_node = Nokogiri::XML.parse("<xliff><file></file></xliff>").xpath("//file").first
23
+ describe '#original' do
24
+ it 'is nil if not defined' do
25
+ xml = Nokogiri::XML.parse('<xliff><file></file></xliff>')
26
+ file_node = xml.xpath('//file').first
25
27
  expect(XLIFF::File.new(file_node).original).to be nil
26
28
  end
27
29
 
28
- it "is the original attribute on file tag" do
29
- file_node = Nokogiri::XML.parse('<xliff><file original="neat file.c"></file></xliff>').xpath("//file").first
30
- expect(XLIFF::File.new(file_node).original).to eql("neat file.c")
30
+ it 'is the original attribute on file tag' do
31
+ xml_text = '<xliff><file original="neat file.c"></file></xliff>'
32
+ xml = Nokogiri::XML.parse(xml_text)
33
+ file_node = xml.xpath('//file').first
34
+ expect(XLIFF::File.new(file_node).original).to eql('neat file.c')
31
35
  end
32
36
  end
33
37
 
34
- describe "#original" do
35
- it "is nil if not defined" do
36
- file_node = Nokogiri::XML.parse("<xliff><file></file></xliff>").xpath("//file").first
37
- expect(XLIFF::File.new(file_node).original).to be nil
38
- end
39
-
40
- it "is the original attribute on file tag" do
41
- file_node = Nokogiri::XML.parse('<xliff><file original="neat file.c"></file></xliff>').xpath("//file").first
42
- expect(XLIFF::File.new(file_node).original).to eql("neat file.c")
43
- end
44
- end
45
-
46
- describe "#source_language" do
47
- it "is nil if not defined" do
48
- file_node = Nokogiri::XML.parse("<xliff><file></file></xliff>").xpath("//file").first
38
+ describe '#source_language' do
39
+ it 'is nil if not defined' do
40
+ xml = Nokogiri::XML.parse('<xliff><file></file></xliff>')
41
+ file_node = xml.xpath('//file').first
49
42
  expect(XLIFF::File.new(file_node).source_language).to be nil
50
43
  end
51
44
 
52
- it "is the original attribute on file tag" do
53
- file_node = Nokogiri::XML.parse('<xliff><file source-language="en"></file></xliff>').xpath("//file").first
54
- expect(XLIFF::File.new(file_node).source_language).to eql("en")
45
+ it 'is the original attribute on file tag' do
46
+ xml_text = '<xliff><file source-language="en"></file></xliff>'
47
+ xml = Nokogiri::XML.parse(xml_text)
48
+ file_node = xml.xpath('//file').first
49
+ expect(XLIFF::File.new(file_node).source_language).to eql('en')
55
50
  end
56
51
  end
57
52
 
58
- describe "#target_language" do
59
- it "is nil if not defined" do
60
- file_node = Nokogiri::XML.parse("<xliff><file></file></xliff>").xpath("//file").first
53
+ describe '#target_language' do
54
+ it 'is nil if not defined' do
55
+ xml = Nokogiri::XML.parse('<xliff><file></file></xliff>')
56
+ file_node = xml.xpath('//file').first
61
57
  expect(XLIFF::File.new(file_node).target_language).to be nil
62
58
  end
63
59
 
64
- it "is the original attribute on file tag" do
65
- file_node = Nokogiri::XML.parse('<xliff><file target-language="fr"></file></xliff>').xpath("//file").first
66
- expect(XLIFF::File.new(file_node).target_language).to eql("fr")
60
+ it 'is the original attribute on file tag' do
61
+ xml_text = '<xliff><file target-language="fr"></file></xliff>'
62
+ xml = Nokogiri::XML.parse(xml_text)
63
+ file_node = xml.xpath('//file').first
64
+ expect(XLIFF::File.new(file_node).target_language).to eql('fr')
67
65
  end
68
66
  end
69
67
 
70
- describe "attribute accessors" do
68
+ describe 'attribute accessors' do
71
69
  let(:subject) do
72
- XLIFF::File.new Nokogiri::XML.parse("<xliff><file></file></xliff>").xpath("//file").first
70
+ xml = Nokogiri::XML.parse('<xliff><file></file></xliff>')
71
+ XLIFF::File.new xml.xpath('//file').first
73
72
  end
74
73
 
75
- describe "source_language=" do
76
- it "changes the source language" do
77
- file_node = Nokogiri::XML.parse('<xliff><file source-language="fr"></file></xliff>').xpath("//file").first
74
+ describe 'source_language=' do
75
+ it 'changes the source language' do
76
+ xml_text = '<xliff><file source-language="fr"></file></xliff>'
77
+ file_node = Nokogiri::XML.parse(xml_text).xpath('//file').first
78
78
  subject = XLIFF::File.new file_node
79
79
  subject.source_language = 'en'
80
80
  expect(subject.source_language).to eq('en')
@@ -86,9 +86,10 @@ module XLIFFer
86
86
  end
87
87
  end
88
88
 
89
- describe "target_language=" do
90
- it "changes the target language" do
91
- file_node = Nokogiri::XML.parse('<xliff><file target-language="fr"></file></xliff>').xpath("//file").first
89
+ describe 'target_language=' do
90
+ it 'changes the target language' do
91
+ xml_text = '<xliff><file target-language="fr"></file></xliff>'
92
+ file_node = Nokogiri::XML.parse(xml_text).xpath('//file').first
92
93
  subject = XLIFF::File.new file_node
93
94
  subject.target_language = 'en'
94
95
  expect(subject.target_language).to eq('en')
@@ -101,7 +102,7 @@ module XLIFFer
101
102
  end
102
103
  end
103
104
 
104
- describe "string accessors" do
105
+ describe 'string accessors' do
105
106
  let(:xml) do
106
107
  <<-EOF
107
108
  <file>
@@ -121,21 +122,21 @@ module XLIFFer
121
122
  end
122
123
 
123
124
  let(:subject) do
124
- XLIFF::File.new(Nokogiri::XML.parse(xml).xpath("//file").first)
125
+ XLIFF::File.new(Nokogiri::XML.parse(xml).xpath('//file').first)
125
126
  end
126
127
 
127
- describe "[]" do
128
- it "gets the string with this id" do
129
- expect(subject['hello'].target).to eq("Bonjour le monde")
128
+ describe '[]' do
129
+ it 'gets the string with this id' do
130
+ expect(subject['hello'].target).to eq('Bonjour le monde')
130
131
  end
131
132
 
132
- it "returns nil if no string found" do
133
+ it 'returns nil if no string found' do
133
134
  expect(subject['non-existent id']).to be_nil
134
135
  end
135
136
  end
136
137
 
137
- describe "[]=" do
138
- it "changes the string target" do
138
+ describe '[]=' do
139
+ it 'changes the string target' do
139
140
  subject['hello'] = 'changed text'
140
141
  expect(subject['hello'].target).to eq('changed text')
141
142
  end
@@ -147,7 +148,7 @@ module XLIFFer
147
148
  end
148
149
  end
149
150
 
150
- describe "#strings" do
151
+ describe '#strings' do
151
152
  let(:trans_unit) do
152
153
  <<-EOF
153
154
  <trans-unit id="my id">
@@ -156,23 +157,28 @@ module XLIFFer
156
157
  </trans-unit>
157
158
  EOF
158
159
  end
159
- it "is an array " do
160
- file_node = Nokogiri::XML.parse("<xliff><file></file></xliff>").xpath("//file").first
160
+ it 'is an array ' do
161
+ xml = Nokogiri::XML.parse('<xliff><file></file></xliff>')
162
+ file_node = xml.xpath('//file').first
161
163
  expect(XLIFF::File.new(file_node).strings).to be_kind_of(Array)
162
164
  end
163
165
 
164
- it "can be empty" do
165
- file_node = Nokogiri::XML.parse("<xliff><file></file></xliff>").xpath("//file").first
166
+ it 'can be empty' do
167
+ xml = Nokogiri::XML.parse('<xliff><file></file></xliff>')
168
+ file_node = xml.xpath('//file').first
166
169
  expect(XLIFF::File.new(file_node).strings).to be_empty
167
170
  end
168
171
 
169
- it "should have a string" do
170
- file_node = Nokogiri::XML.parse("<xliff><file>#{trans_unit}</file></xliff>").xpath("//file").first
172
+ it 'should have a string' do
173
+ xml = Nokogiri::XML.parse("<xliff><file>#{trans_unit}</file></xliff>")
174
+ file_node = xml.xpath('//file').first
171
175
  expect(XLIFF::File.new(file_node).strings.size).to eql(1)
172
176
  end
173
177
 
174
- it "should have multiple strings" do
175
- file_node = Nokogiri::XML.parse("<xliff><file>#{trans_unit * 10}</file></xliff>").xpath("//file").first
178
+ it 'should have multiple strings' do
179
+ xml_text = "<xliff><file>#{trans_unit * 10}</file></xliff>"
180
+ xml = Nokogiri::XML.parse(xml_text)
181
+ file_node = xml.xpath('//file').first
176
182
  expect(XLIFF::File.new(file_node).strings.size).to eql(10)
177
183
  end
178
184
  end
@@ -12,57 +12,76 @@ module XLIFFer
12
12
  EOF
13
13
  end
14
14
 
15
- describe "#new" do
16
- it "is created with a nokogiri trans-unit node" do
17
- trans_unit_node = Nokogiri::XML.parse(trans_unit).xpath("//trans-unit").first
15
+ let(:xml) do
16
+ Nokogiri::XML.parse(trans_unit)
17
+ end
18
+
19
+ describe '#new' do
20
+ it 'is created with a nokogiri trans-unit node' do
21
+ trans_unit_node = xml.xpath('//trans-unit').first
18
22
  expect(XLIFF::String.new(trans_unit_node)).to be
19
23
  end
20
24
 
21
25
  it "can't be created with a string" do
22
- expect{XLIFF::String.new("<file></file>")}.to raise_error ArgumentError
26
+ expect {
27
+ XLIFF::String.new('<file></file>')
28
+ }.to raise_error ArgumentError
23
29
  end
24
30
 
25
31
  it "can't be created with a node that is not a file node" do
26
- trans_unit_node = Nokogiri::XML.parse("<xliff></xliff>").xpath("/xliff").first
27
- expect{XLIFF::String.new(trans_unit_node)}.to raise_error ArgumentError
32
+ xml = Nokogiri::XML.parse('<xliff></xliff>')
33
+ trans_unit_node = xml.xpath('/xliff').first
34
+ expect {
35
+ XLIFF::String.new(trans_unit_node)
36
+ }.to raise_error ArgumentError
28
37
  end
29
38
 
30
- it "have one source" do
31
- xml = "<trans-unit><target></target></trans-unit>"
32
- trans_unit_node = Nokogiri::XML.parse(xml).xpath("//trans-unit").first
33
- expect{XLIFF::String.new(trans_unit_node)}.to raise_error NoElement
39
+ it 'have one source' do
40
+ xml = '<trans-unit><target></target></trans-unit>'
41
+ trans_unit_node = Nokogiri::XML.parse(xml).xpath('//trans-unit').first
42
+ expect { XLIFF::String.new(trans_unit_node) }.to raise_error NoElement
34
43
  end
35
44
 
36
45
  it "don't have multiple sources tag" do
37
- xml = "<trans-unit>#{"<source></source>"*2}<target></target></trans-unit>"
38
- trans_unit_node = Nokogiri::XML.parse(xml).xpath("//trans-unit").first
39
- expect{XLIFF::String.new(trans_unit_node)}.to raise_error MultipleElement
46
+ xml = '<trans-unit>'
47
+ xml += "#{'<source></source>' * 2}<target></target>"
48
+ xml += '</trans-unit>'
49
+ trans_unit_node = Nokogiri::XML.parse(xml).xpath('//trans-unit').first
50
+ expect {
51
+ XLIFF::String.new(trans_unit_node)
52
+ }.to raise_error MultipleElement
40
53
  end
41
54
 
42
55
  it "don't have multiple targets tag" do
43
- xml = "<trans-unit><source></source>#{"<target></target>"*2}</trans-unit>"
44
- trans_unit_node = Nokogiri::XML.parse(xml).xpath("//trans-unit").first
45
- expect{XLIFF::String.new(trans_unit_node)}.to raise_error MultipleElement
56
+ xml = '<trans-unit>'
57
+ xml += "<source></source>#{'<target></target>' * 2}"
58
+ xml += '</trans-unit>'
59
+ trans_unit_node = Nokogiri::XML.parse(xml).xpath('//trans-unit').first
60
+ expect {
61
+ XLIFF::String.new(trans_unit_node)
62
+ }.to raise_error MultipleElement
46
63
  end
47
64
  end
48
65
 
49
- describe "#id" do
50
- it "is nil if not defined" do
51
- xml = "<trans-unit><source></source><target></target></trans-unit>"
52
- trans_unit_node = Nokogiri::XML.parse(xml).xpath("//trans-unit").first
66
+ describe '#id' do
67
+ it 'is nil if not defined' do
68
+ xml = '<trans-unit><source></source><target></target></trans-unit>'
69
+ trans_unit_node = Nokogiri::XML.parse(xml).xpath('//trans-unit').first
53
70
  expect(XLIFF::String.new(trans_unit_node).id).to be nil
54
71
  end
55
72
 
56
- it "is the id attribute on trans-unit tag" do
57
- xml = "<trans-unit id='my id'><source></source><target></target></trans-unit>"
58
- trans_unit_node = Nokogiri::XML.parse(xml).xpath("//trans-unit").first
59
- expect(XLIFF::String.new(trans_unit_node).id).to eql("my id")
73
+ it 'is the id attribute on trans-unit tag' do
74
+ xml = "<trans-unit id='my id'>"
75
+ xml += '<source></source><target></target>'
76
+ xml += '</trans-unit>'
77
+ trans_unit_node = Nokogiri::XML.parse(xml).xpath('//trans-unit').first
78
+ expect(XLIFF::String.new(trans_unit_node).id).to eql('my id')
60
79
  end
61
80
  end
62
81
 
63
- describe "#target=" do
82
+ describe '#target=' do
64
83
  it 'Modify target' do
65
- trans_unit_node = Nokogiri::XML.parse(trans_unit).xpath("//trans-unit").first
84
+ trans_unit_node = xml.xpath('//trans-unit').first
66
85
  string = XLIFF::String.new(trans_unit_node)
67
86
  string.target = 'Hola Mundo'
68
87
  expect(string.target).to eq 'Hola Mundo'
@@ -71,7 +90,7 @@ module XLIFFer
71
90
  context 'when target do not exist' do
72
91
  it 'add a new target' do
73
92
  xml = "<trans-unit id='my id'><source>Value</source></trans-unit>"
74
- trans_unit_node = Nokogiri::XML.parse(xml).xpath("//trans-unit").first
93
+ trans_unit_node = Nokogiri::XML.parse(xml).xpath('//trans-unit').first
75
94
  string = XLIFF::String.new(trans_unit_node)
76
95
  string.target = 'Hola Mundo'
77
96
  expect(string.target).to eq 'Hola Mundo'
@@ -79,9 +98,9 @@ module XLIFFer
79
98
  end
80
99
  end
81
100
 
82
- describe "#source=" do
101
+ describe '#source=' do
83
102
  it 'Modify source' do
84
- trans_unit_node = Nokogiri::XML.parse(trans_unit).xpath("//trans-unit").first
103
+ trans_unit_node = xml.xpath('//trans-unit').first
85
104
  string = XLIFF::String.new(trans_unit_node)
86
105
  string.source = 'Hola Mundo'
87
106
  expect(string.source).to eq 'Hola Mundo'
@@ -2,70 +2,82 @@ require 'spec_helper'
2
2
 
3
3
  module XLIFFer
4
4
  describe XLIFF do
5
- describe "#new" do
6
- it "accepts a xliff file" do
7
- expect(XLIFF.new(::File.open("spec/files/empty.xliff"))).to be
5
+ describe '#new' do
6
+ it 'accepts a xliff file' do
7
+ expect(XLIFF.new(::File.open('spec/files/empty.xliff'))).to be
8
8
  end
9
9
 
10
- it "accepts a xliff string" do
11
- expect(XLIFF.new(::File.open("spec/files/empty.xliff").read)).to be
10
+ it 'accepts a xliff string' do
11
+ expect(XLIFF.new(::File.open('spec/files/empty.xliff').read)).to be
12
12
  end
13
13
 
14
14
  it "doesn't accept a number" do
15
- expect{XLIFF.new(123)}.to raise_error ArgumentError
15
+ expect { XLIFF.new(123) }.to raise_error ArgumentError
16
16
  end
17
17
 
18
18
  it "doesn't accept a random string" do
19
- expect{XLIFF.new("foobar")}.to raise_error FormatError
19
+ expect { XLIFF.new('foobar') }.to raise_error FormatError
20
20
  end
21
21
 
22
22
  it "doesn't accept a random file" do
23
- expect{XLIFF.new(::File.new("spec/files/file.foobar"))}.to raise_error FormatError
23
+ expect {
24
+ XLIFF.new(::File.new('spec/files/file.foobar'))
25
+ }.to raise_error FormatError
24
26
  end
25
27
  end
26
28
 
27
- describe "#version" do
28
- it "is the xliff version" do
29
- expect(XLIFF.new('<xliff version="9.8"></xliff>').version).to eql("9.8")
29
+ describe '#version' do
30
+ it 'is the xliff version' do
31
+ expect(
32
+ XLIFF.new('<xliff version="9.8"></xliff>').version
33
+ ).to eql('9.8')
30
34
  end
31
35
 
32
- it "is nil when it is not present" do
36
+ it 'is nil when it is not present' do
33
37
  expect(XLIFF.new('<xliff></xliff>').version).to be_nil
34
38
  end
35
39
 
36
- it "is a string when there is a xliff version" do
37
- expect(XLIFF.new('<xliff version="9.8"></xliff>').version).to be_kind_of(String)
40
+ it 'is a string when there is a xliff version' do
41
+ expect(
42
+ XLIFF.new('<xliff version="9.8"></xliff>').version
43
+ ).to be_kind_of(String)
38
44
  end
39
45
  end
40
46
 
41
- describe "#files" do
42
- it "is an array " do
43
- expect(XLIFF.new('<xliff></xliff>').files).to be_kind_of(Array)
47
+ describe '#files' do
48
+ it 'is an array ' do
49
+ expect(
50
+ XLIFF.new('<xliff></xliff>').files
51
+ ).to be_kind_of(Array)
44
52
  end
45
53
 
46
- it "can be empty" do
54
+ it 'can be empty' do
47
55
  expect(XLIFF.new('<xliff></xliff>').files).to be_empty
48
56
  end
49
57
 
50
- it "should have a file" do
51
- expect(XLIFF.new('<xliff><file></file></xliff>').files.first).to be_kind_of(XLIFF::File)
58
+ it 'should have a file' do
59
+ expect(
60
+ XLIFF.new('<xliff><file></file></xliff>').files.first
61
+ ).to be_kind_of(XLIFF::File)
52
62
  end
53
63
 
54
- it "should have multiple files" do
55
- expect(XLIFF.new('<xliff><file></file><file></file></xliff>').files.size).to eql(2)
64
+ it 'should have multiple files' do
65
+ expect(
66
+ XLIFF.new('<xliff><file></file><file></file></xliff>').files.size
67
+ ).to eql(2)
56
68
  end
57
69
  end
58
70
 
59
- describe "#to_s" do
71
+ describe '#to_s' do
60
72
  it 'outputs a xml' do
61
- xml = ::File.open("spec/files/simple.xliff").read
73
+ xml = ::File.open('spec/files/simple.xliff').read
62
74
  xliff = XLIFF.new(xml)
63
75
  expect(Nokogiri::XML(xliff.to_s)).to be
64
76
  end
65
77
 
66
78
  context 'when xml is not changed' do
67
79
  it 'outputs the same xml' do
68
- xml = ::File.open("spec/files/simple.xliff").read
80
+ xml = ::File.open('spec/files/simple.xliff').read
69
81
  xliff = XLIFF.new(xml)
70
82
  expect(xliff.to_s).to be_equivalent_to(xml)
71
83
  end
@@ -73,9 +85,9 @@ module XLIFFer
73
85
 
74
86
  context 'when xml is changed' do
75
87
  it 'outputs a different xml' do
76
- xml = ::File.open("spec/files/simple.xliff").read
88
+ xml = ::File.open('spec/files/simple.xliff').read
77
89
  xliff = XLIFF.new(xml)
78
- xliff.files.first.strings.first.target = "My brand new target"
90
+ xliff.files.first.strings.first.target = 'My brand new target'
79
91
  expect(xliff.to_s).not_to be_equivalent_to(xml)
80
92
  end
81
93
  end
@@ -1,27 +1,29 @@
1
- $:.push File.expand_path("../lib", __FILE__)
1
+ $LOAD_PATH.push File.expand_path('../lib', __FILE__)
2
2
  require 'xliffer/version'
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = 'xliffer'
6
6
  s.version = XLIFFer::VERSION
7
7
  s.platform = Gem::Platform::RUBY
8
- s.licenses = ["MIT"]
8
+ s.licenses = ['MIT']
9
9
  s.date = '2012-01-01'
10
- s.summary = "A XLIFF parser"
11
- s.description = "A parser for XLIFF files"
12
- s.authors = ["Felipe Tanus"]
10
+ s.summary = 'A XLIFF parser'
11
+ s.description = 'A parser for XLIFF files'
12
+ s.authors = ['Felipe Tanus']
13
13
  s.email = 'fotanus@gmail.com'
14
14
  s.homepage = 'http://github.com/fotanus/xliff'
15
15
 
16
- s.add_dependency "nokogiri", "~> 1.5"
16
+ s.add_dependency 'nokogiri', '~> 1.5'
17
17
 
18
- s.add_development_dependency "rspec", "~> 2"
19
- s.add_development_dependency "simplecov", "~> 0.10"
18
+ s.add_development_dependency 'rspec', '~> 2'
19
+ s.add_development_dependency 'simplecov', '~> 0.10'
20
20
 
21
- s.rubyforge_project = "xliffer"
21
+ s.rubyforge_project = 'xliffer'
22
22
 
23
23
  s.files = `git ls-files`.split("\n")
24
24
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
25
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
26
- s.require_paths = ["lib"]
25
+ s.executables = `git ls-files -- bin/*`.split("\n").map do |f|
26
+ File.basename(f)
27
+ end
28
+ s.require_paths = ['lib']
27
29
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xliffer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felipe Tanus
@@ -60,6 +60,7 @@ extra_rdoc_files: []
60
60
  files:
61
61
  - ".gitignore"
62
62
  - ".rspec"
63
+ - ".rubocop.yml"
63
64
  - ".travis.yml"
64
65
  - Gemfile
65
66
  - LICENSE.md
@@ -102,8 +103,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
103
  version: '0'
103
104
  requirements: []
104
105
  rubyforge_project: xliffer
105
- rubygems_version: 2.4.6
106
+ rubygems_version: 2.4.8
106
107
  signing_key:
107
108
  specification_version: 4
108
109
  summary: A XLIFF parser
109
110
  test_files: []
111
+ has_rdoc: