tmx-parser 1.0.1 → 1.1.0

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: da549d0476558c832213a9f4e25b1c9f7fbfbba6
4
- data.tar.gz: 463eb23b99f433b2ecd3700be334451d34b1920e
3
+ metadata.gz: ef8ec0ddafa950c82b58e16755924891ab2a8050
4
+ data.tar.gz: c252936547061bb05ec155566ee4badb008379b2
5
5
  SHA512:
6
- metadata.gz: 87dac736b726a75e6bb838775f591a133304aba12a9e24179c16f1b0f7a76d4fb82912259ffd0a9ffcde888ecf288dfc9de6504a6c2b3592e82159182b7a8de9
7
- data.tar.gz: 182b8ca9b936d29055c4c9181657f439d05ddbbcbc22aac78d98b4c756bbdb71284ac44ba44b3d96a1b59663789129f6f8ee0a8852b18ed88f07a618c1798e53
6
+ metadata.gz: 1913a5ddbff10fe170097d76e11771240485fea5415bea4ae3187800ad61aa6dee1d51b113aebdfa0c9015a6cbf22d56968314e965d89f2f28c218fbf8a1b23e
7
+ data.tar.gz: 606c7d648d9d42df21cef827080f0304f829dfc27a20d9430e9799ee343694c8d2923a806c8e2ddf0054b30cb5556b6030db517fb5ff30d3bb7af98b5b10ed1e
@@ -1,7 +1,11 @@
1
+ == 1.0.0
2
+
3
+ * Birthday!
4
+
1
5
  == 1.0.1
2
6
 
3
7
  * Add ability to specify encoding.
4
8
 
5
- == 1.0.0
9
+ == 1.1.0
6
10
 
7
- * Birthday!
11
+ * Add #copy and #== methods to elements.
@@ -11,18 +11,46 @@ module TmxParser
11
11
  @properties = {}
12
12
  @variants = []
13
13
  end
14
+
15
+ def copy
16
+ self.class.new(tuid.dup, segtype.dup).tap do |new_unit|
17
+ new_unit.variants.concat(variants.map(&:copy))
18
+ properties.each do |key, property_value|
19
+ new_unit.properties[key] = property_value.copy
20
+ end
21
+ end
22
+ end
23
+
24
+ def ==(other_unit)
25
+ tuid == other_unit.tuid &&
26
+ segtype == other_unit.segtype &&
27
+ variants.each_with_index.all? do |v, idx|
28
+ other_unit.variants[idx] == v
29
+ end &&
30
+ properties.each_with_index.all? do |(key, prop_val), idx|
31
+ other_unit.properties[key] == prop_val
32
+ end
33
+ end
14
34
  end
15
35
 
16
36
  class PropertyValue
17
37
  attr_accessor :value
18
38
 
19
- def initialize
20
- @value = ''
39
+ def initialize(init_value = '')
40
+ @value = init_value
21
41
  end
22
42
 
23
43
  def receive_text(str)
24
44
  @value << str
25
45
  end
46
+
47
+ def copy
48
+ self.class.new(value.dup)
49
+ end
50
+
51
+ def ==(other_property_value)
52
+ value == other_property_value.value
53
+ end
26
54
  end
27
55
 
28
56
  class Variant
@@ -37,28 +65,59 @@ module TmxParser
37
65
  def receive_text(str)
38
66
  @elements << str
39
67
  end
68
+
69
+ def copy
70
+ self.class.new(locale.dup).tap do |new_variant|
71
+ new_variant.elements.concat(
72
+ elements.map do |element|
73
+ element.respond_to?(:copy) ? element.copy : element.dup
74
+ end
75
+ )
76
+ end
77
+ end
78
+
79
+ def ==(other_variant)
80
+ locale == locale &&
81
+ elements.each_with_index.all? do |element, idx|
82
+ other_variant.elements[idx] == element
83
+ end
84
+ end
40
85
  end
41
86
 
42
87
  class Placeholder
43
88
  attr_reader :type, :text
44
89
  attr_accessor :start, :length
45
90
 
46
- def initialize(type)
91
+ def initialize(type, text = '')
47
92
  @type = type
48
- @text = ''
93
+ @text = text
49
94
  end
50
95
 
51
96
  def receive_text(str)
52
97
  @text << str
53
98
  end
99
+
100
+ def copy
101
+ self.class.new(type.dup, text.dup).tap do |new_placeholder|
102
+ new_placeholder.start = start # can't dup fixnums
103
+ new_placeholder.length = length
104
+ end
105
+ end
106
+
107
+ def ==(other_placeholder)
108
+ type == other_placeholder.type &&
109
+ text == other_placeholder.type &&
110
+ start == other_placeholder.start &&
111
+ length == other_placeholder.length
112
+ end
54
113
  end
55
114
 
56
115
  class Pair
57
116
  attr_reader :text, :i
58
117
 
59
- def initialize(i)
118
+ def initialize(i, text = '')
60
119
  @i = i
61
- @text = ''
120
+ @text = text
62
121
  end
63
122
 
64
123
  def receive_text(str)
@@ -68,6 +127,16 @@ module TmxParser
68
127
  def type
69
128
  raise NotImplementedError
70
129
  end
130
+
131
+ def copy
132
+ self.class.new(i, text.dup)
133
+ end
134
+
135
+ def ==(other_pair)
136
+ i == other_pair.i &&
137
+ text == other_pair.text &&
138
+ type == other_pair.type
139
+ end
71
140
  end
72
141
 
73
142
  class BeginPair < Pair
@@ -1,5 +1,5 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  module TmxParser
4
- VERSION = '1.0.1'
4
+ VERSION = '1.1.0'
5
5
  end
@@ -26,6 +26,52 @@ describe TmxParser do
26
26
  }
27
27
  end
28
28
 
29
+ describe '#copy' do
30
+ it 'deep copies the tree' do
31
+ parser.load(document).to_a.tap do |units|
32
+ original_unit = units.first
33
+ unit_copy = original_unit.copy
34
+
35
+ expect(unit_copy.tuid).to eq(original_unit.tuid)
36
+ expect(unit_copy.segtype).to eq(original_unit.segtype)
37
+ expect(unit_copy.variants.size).to eq(original_unit.variants.size)
38
+
39
+ unit_copy.properties.each_pair.with_index do |(key, prop_value_copy), idx|
40
+ original_prop_value = original_unit.properties[key]
41
+ expect(original_prop_value.value).to eq(prop_value_copy.value)
42
+ end
43
+
44
+ unit_copy.variants.each_with_index do |variant_copy, v_idx|
45
+ original_variant = original_unit.variants[v_idx]
46
+ expect(variant_copy.locale).to eq(original_variant.locale)
47
+
48
+ variant_copy.elements.each_with_index do |element_copy, e_idx|
49
+ original_element = original_variant.elements[e_idx]
50
+ expect(element_copy).to be_a(original_element.class)
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+
57
+ describe '#==' do
58
+ it 'returns true if the objects (even copies) are equivalent' do
59
+ parser.load(document).to_a.tap do |units|
60
+ expect(units.first).to eq(units.first.copy)
61
+ end
62
+ end
63
+
64
+ it 'returns false if the objects are not equivalent' do
65
+ parser.load(document).to_a.tap do |units|
66
+ unit = units.first
67
+ unit_copy = unit.copy
68
+
69
+ unit_copy.tuid.replace('foobar')
70
+ expect(unit).to_not eq(unit_copy)
71
+ end
72
+ end
73
+ end
74
+
29
75
  it 'identifies the tuid and segtype' do
30
76
  parser.load(document).to_a.tap do |units|
31
77
  expect(units.size).to eq(1)
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tmx-parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cameron Dutro
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-24 00:00:00.000000000 Z
11
+ date: 2015-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
+ name: nokogiri
14
15
  requirement: !ruby/object:Gem::Requirement
15
16
  requirements:
16
- - - ~>
17
+ - - "~>"
17
18
  - !ruby/object:Gem::Version
18
19
  version: 1.6.0
19
- name: nokogiri
20
- prerelease: false
21
20
  type: :runtime
21
+ prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.6.0
27
27
  - !ruby/object:Gem::Dependency
28
+ name: pry-nav
28
29
  requirement: !ruby/object:Gem::Requirement
29
30
  requirements:
30
- - - ~>
31
+ - - "~>"
31
32
  - !ruby/object:Gem::Version
32
33
  version: 0.2.0
33
- name: pry-nav
34
- prerelease: false
35
34
  type: :development
35
+ prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.2.0
41
41
  - !ruby/object:Gem::Dependency
42
+ name: rspec
42
43
  requirement: !ruby/object:Gem::Requirement
43
44
  requirements:
44
- - - ~>
45
+ - - "~>"
45
46
  - !ruby/object:Gem::Version
46
47
  version: 3.2.0
47
- name: rspec
48
- prerelease: false
49
48
  type: :development
49
+ prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: 3.2.0
55
55
  description: Parser for the Translation Memory eXchange (.tmx) file format.
@@ -59,6 +59,10 @@ executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
+ - Gemfile
63
+ - History.txt
64
+ - README.md
65
+ - Rakefile
62
66
  - lib/tmx-parser.rb
63
67
  - lib/tmx-parser/document.rb
64
68
  - lib/tmx-parser/elements.rb
@@ -68,32 +72,28 @@ files:
68
72
  - lib/tmx-parser/version.rb
69
73
  - spec/spec_helper.rb
70
74
  - spec/tmx-parser_spec.rb
71
- - Gemfile
72
- - History.txt
73
- - README.md
74
- - Rakefile
75
75
  - tmx-parser.gemspec
76
76
  homepage: http://github.com/camertron
77
77
  licenses: []
78
78
  metadata: {}
79
- post_install_message:
79
+ post_install_message:
80
80
  rdoc_options: []
81
81
  require_paths:
82
82
  - lib
83
83
  required_ruby_version: !ruby/object:Gem::Requirement
84
84
  requirements:
85
- - - '>='
85
+ - - ">="
86
86
  - !ruby/object:Gem::Version
87
87
  version: '0'
88
88
  required_rubygems_version: !ruby/object:Gem::Requirement
89
89
  requirements:
90
- - - '>='
90
+ - - ">="
91
91
  - !ruby/object:Gem::Version
92
92
  version: '0'
93
93
  requirements: []
94
- rubyforge_project:
95
- rubygems_version: 2.1.9
96
- signing_key:
94
+ rubyforge_project:
95
+ rubygems_version: 2.2.3
96
+ signing_key:
97
97
  specification_version: 4
98
98
  summary: Parser for the Translation Memory eXchange (.tmx) file format.
99
99
  test_files: []