konjak 0.0.3 → 0.0.4

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: 1aae6a0828c217fabb68f93b53d248f366b4e045
4
- data.tar.gz: 1fa12203b343240a4881ddad7f6882d1e5657a39
3
+ metadata.gz: ea6b25de9fe1bb666b02b8db7a3253619fe6cc5b
4
+ data.tar.gz: 4bf4b8cdc708b5904c16e8d3b656c37b15c26f4e
5
5
  SHA512:
6
- metadata.gz: 3f7e4203d4abd4afd6a5f4f500ed59b8ec69307544d3da42691270b010e27c7c0456cbb12d4096f2add1d239a5e30b06684ff5b1e29c337caece14b7c2649437
7
- data.tar.gz: a7a486bc844b11fd58322ec8f49386b3a2520860e5f20e69b835332336609b2a6477313fff7eb8abfb574137830c8566700c822327b286f7eb4073fcdf14af0c
6
+ metadata.gz: 94607b5df832840753b9a863dec409c98a283d9be758f40be2af1522cdd0815fe7615390f868fd2afa89133046a9418de25b1c568146cc5f3ceb491854c423c6
7
+ data.tar.gz: bef5ef91e252bfadde9f6b8f6cb8fd6674efd4ae4e2d4c28a4f65e88c9a0330e365faf7fe4ced678a56a876f185dd8dac0d87f3877ef4d13f7d12be4939a94f1
data/.travis.yml CHANGED
@@ -3,4 +3,5 @@ rvm:
3
3
  - 2.2
4
4
  env:
5
5
  global:
6
- secure: V8yG0G03Dsabc5mK4ubx3wSd0FyW0tazC/4DsJrvQTXSNytab1tXpwQbaN1XUyWTGnOj58mSZAPk/36n/5sGEwq3HIYCvPbJrqrCRODTDzmYy5uA1N+/Mo2uA55lPBjCbfcEvO1oy9tQIcH3I3R29nqiTsIRXax8XoFXHlJdP7I=
6
+ - secure: V8yG0G03Dsabc5mK4ubx3wSd0FyW0tazC/4DsJrvQTXSNytab1tXpwQbaN1XUyWTGnOj58mSZAPk/36n/5sGEwq3HIYCvPbJrqrCRODTDzmYy5uA1N+/Mo2uA55lPBjCbfcEvO1oy9tQIcH3I3R29nqiTsIRXax8XoFXHlJdP7I=
7
+ - secure: MghViLairF+zNTbCoH/ibECjud2Wf+6K3qKDIbo1dkxqzU4xIILDtODUmlLTQh0Da/IbAmTIc0XV5GgnftoiDIg9s6PQRhNeQX3heA6ElxwmOZmKNvcSutxZLm0AT3/PPZluykg5KBoETZQEAXLVamwbKiGCM9eIlTwOqRrHDRI=
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # Konjak
2
2
 
3
- [![Build Status](https://travis-ci.org/hanachin/konjak.svg)](https://travis-ci.org/hanachin/konjak)
4
- [![Code Climate](https://codeclimate.com/github/hanachin/konjak/badges/gpa.svg)](https://codeclimate.com/github/hanachin/konjak)
5
- [![Test Coverage](https://codeclimate.com/github/hanachin/konjak/badges/coverage.svg)](https://codeclimate.com/github/hanachin/konjak/coverage)
3
+ [![Build Status](https://travis-ci.org/yasslab/konjak.svg?branch=v0.0.1)](https://travis-ci.org/yasslab/konjak)
4
+ [![Code Climate](https://codeclimate.com/github/yasslab/konjak/badges/gpa.svg)](https://codeclimate.com/github/yasslab/konjak)
5
+ [![Test Coverage](https://codeclimate.com/github/yasslab/konjak/badges/coverage.svg)](https://codeclimate.com/github/yasslab/konjak/coverage)
6
6
 
7
7
  TMX(Translation Memory eXchange) tools for ruby
8
8
 
@@ -26,7 +26,7 @@ Or install it yourself as:
26
26
 
27
27
  ## Contributing
28
28
 
29
- 1. Fork it ( http://github.com/hanachin/konjak/fork )
29
+ 1. Fork it ( http://github.com/yasslab/konjak/fork )
30
30
  2. Create your feature branch (`git checkout -b my-new-feature`)
31
31
  3. Commit your changes (`git commit -am 'Add some feature'`)
32
32
  4. Push to the branch (`git push origin my-new-feature`)
data/konjak.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["hanachin@gmail.com"]
11
11
  spec.summary = %q{TMX(Translation Memory exChange) tools for ruby}
12
12
  spec.description = %q{TMX(Translation Memory exChange) tools for ruby}
13
- spec.homepage = "https://github.com/hanachin/konjak"
13
+ spec.homepage = "https://github.com/yasslab/konjak"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
@@ -1,11 +1,13 @@
1
1
  module Konjak
2
2
  class BeginPairedTag < InlineElement
3
3
  # required attrs
4
- attr_accessor :i
4
+ tmx_attr_accessor(:i, required: true)
5
5
 
6
6
  # optional attrs
7
- attr_accessor :x, :type
7
+ tmx_attr_accessor(:x)
8
+ tmx_attr_accessor(:type)
8
9
 
10
+ # methods
9
11
  def can_contain?(element)
10
12
  CodeData === element || SubFlow === element
11
13
  end
data/lib/konjak/body.rb CHANGED
@@ -1,12 +1,11 @@
1
1
  module Konjak
2
2
  class Body < StructuralElement
3
- # children
4
- attr_accessor :translation_units
5
-
6
- def initialize(body)
7
- @translation_units = body.children.select {|c| c.name == 'tu' }.map {|tu| TranslationUnit.new tu }
3
+ # childrens
4
+ def translation_units
5
+ children.select {|c| c.name == 'tu' }.map {|tu| TranslationUnit.new(tu) }
8
6
  end
9
7
 
8
+ # methods
10
9
  def can_contain?(element)
11
10
  TranslationUnit === element
12
11
  end
@@ -1,5 +1,25 @@
1
+ require 'delegate'
2
+
1
3
  module Konjak
2
- class Element
3
- attr_accessor :child_elements
4
+ class Element < Delegator
5
+ def initialize(__element__)
6
+ @__element__ = __element__
7
+ end
8
+
9
+ def __getobj__
10
+ @__element__
11
+ end
12
+
13
+ private
14
+
15
+ def self.tmx_attr_accessor(name, attr_name=name, required: false)
16
+ define_method(name) do
17
+ self[attr_name]
18
+ end
19
+
20
+ define_method("#{name}=") do |value|
21
+ self[attr_name] = value
22
+ end
23
+ end
4
24
  end
5
25
  end
@@ -1,8 +1,9 @@
1
1
  module Konjak
2
2
  class EndPairedTag < InlineElement
3
3
  # required attrs
4
- attr_accessor :i
4
+ tmx_attr_accessor(:i, required: true)
5
5
 
6
+ # methods
6
7
  def can_contain?(element)
7
8
  CodeData === element || SubFlow === element
8
9
  end
data/lib/konjak/header.rb CHANGED
@@ -1,37 +1,35 @@
1
1
  module Konjak
2
2
  class Header < StructuralElement
3
3
  # required attrs
4
- attr_accessor :creation_tool, :creation_tool_version, :seg_type, :o_tmf, :admin_lang, :src_lang, :data_type
4
+ tmx_attr_accessor(:creation_tool, :creationtool, required: true)
5
+ tmx_attr_accessor(:creation_tool_version, :creationtoolversion, required: true)
6
+ tmx_attr_accessor(:seg_type, :segtype, required: true)
7
+ tmx_attr_accessor(:o_tmf, :"o-tmf", required: true)
8
+ tmx_attr_accessor(:admin_lang, :adminlang, required: true)
9
+ tmx_attr_accessor(:src_lang, :srclang, required: true)
10
+ tmx_attr_accessor(:data_type, :datatype, required: true)
5
11
 
6
12
  # optional attrs
7
- attr_accessor :o_encoding, :creation_date, :creation_id, :change_date, :change_id
13
+ tmx_attr_accessor(:o_encoding, :"o-encoding")
14
+ tmx_attr_accessor(:creation_date, :creationdate)
15
+ tmx_attr_accessor(:creation_id, :creationid)
16
+ tmx_attr_accessor(:change_date, :changedate)
17
+ tmx_attr_accessor(:change_id, :changeid)
8
18
 
9
- # children
10
- attr_accessor :notes, :user_defined_encodings, :properties
11
-
12
- def initialize(header)
13
- # required attrs
14
- @creation_tool = header[:creationtool]
15
- @creation_tool_version = header[:creationtoolversion]
16
- @seg_type = header[:segtype]
17
- @o_tmf = header[:"o-tmf"]
18
- @admin_lang = header[:adminlang]
19
- @src_lang = header[:srclang]
20
- @data_type = header[:datatype]
19
+ # childrens
20
+ def notes
21
+ children.select {|c| c.name == 'note' }.map {|n| Note.new(n) }
22
+ end
21
23
 
22
- # optional attrs
23
- @o_encoding = header[:"o-encoding"]
24
- @creation_date = header[:creationdate]
25
- @creation_id = header[:creationid]
26
- @change_date = header[:changedate]
27
- @change_id = header[:changeid]
24
+ def user_defined_encodings
25
+ children.select {|c| c.name == 'ude' }.map {|n| UserDefinedEncoding.new(n) }
26
+ end
28
27
 
29
- # children
30
- @notes = header.children.select {|c| c.name == 'note' }.map {|n| Note.new n }
31
- @user_defined_encodings = header.children.select {|c| c.name == 'ude' }.map {|n| UserDefinedEncoding.new n }
32
- @properties = header.children.select {|c| c.name == 'prop' }.map {|n| Property.new n }
28
+ def properties
29
+ children.select {|c| c.name == 'prop' }.map {|n| Property.new(n) }
33
30
  end
34
31
 
32
+ # methods
35
33
  def can_contain?(element)
36
34
  [Note, UserDefinedEncoding, Property].any? {|c| c === element }
37
35
  end
@@ -1,7 +1,10 @@
1
1
  module Konjak
2
2
  class Hilight < InlineElement
3
3
  # optional attrs
4
- attr_accessor :x, :type
4
+ tmx_attr_accessor(:x)
5
+ tmx_attr_accessor(:type)
6
+
7
+ # methods
5
8
 
6
9
  # FIXME
7
10
  # Text data,
@@ -1,11 +1,13 @@
1
1
  module Konjak
2
2
  class IsolatedTag < InlineElement
3
3
  # required attrs
4
- attr_accessor :pos
4
+ tmx_attr_accessor(:pos, required: true)
5
5
 
6
6
  # optional attrs
7
- attr_accessor :x, :type
7
+ tmx_attr_accessor(:x)
8
+ tmx_attr_accessor(:type)
8
9
 
10
+ # methods
9
11
  def can_contain?(element)
10
12
  CodeData === element || SubFlow === element
11
13
  end
data/lib/konjak/map.rb CHANGED
@@ -1,17 +1,14 @@
1
1
  module Konjak
2
2
  class Map < StructuralElement
3
3
  # required attrs
4
- attr_accessor :unicode
4
+ tmx_attr_accessor(:unicode, required: true)
5
5
 
6
6
  # optional attrs
7
- attr_accessor :code, :entity, :substitution
7
+ tmx_attr_accessor(:code)
8
+ tmx_attr_accessor(:entity, :ent)
9
+ tmx_attr_accessor(:substitution, :subst)
8
10
 
9
- def initialize(map)
10
- @unicode = map[:unicode]
11
- @code = map[:code]
12
- @entity = map[:ent]
13
- @substitution = map[:subst]
14
- end
11
+ # methods
15
12
 
16
13
  # FIXME:
17
14
  # code, ent and subst. At least one of these attributes should be specified.
data/lib/konjak/note.rb CHANGED
@@ -1,17 +1,15 @@
1
1
  module Konjak
2
2
  class Note < StructuralElement
3
3
  # optional attrs
4
- attr_accessor :xml_lang, :o_encoding
4
+ tmx_attr_accessor(:xml_lang, :'xml:lang')
5
+ tmx_attr_accessor(:o_encoding, :"o-encoding")
5
6
 
6
- # text
7
- attr_accessor :text
8
-
9
- def initialize(note)
10
- @xml_lang = note["xml:lang"]
11
- @o_encoding = note["o-encoding"]
12
- @text = Text.new(note.text)
7
+ # childrens
8
+ def text
9
+ Text.new(super)
13
10
  end
14
11
 
12
+ # methods
15
13
  def can_contain?(element)
16
14
  Text === element
17
15
  end
data/lib/konjak/parser.rb CHANGED
@@ -7,8 +7,8 @@ module Konjak
7
7
  # FIXME
8
8
  xml = xml.gsub(/&amp;(#\d+|#x[0-9a-fA-F]+|[0-9a-zA-Z]+);/) { "&#{$1};" }
9
9
  end
10
- doc = Nokogiri::XML.parse(xml) {|c| c.noblanks }
11
- Tmx.new doc.root
10
+ doc = Nokogiri::XML.parse(xml)
11
+ Tmx.new doc
12
12
  end
13
13
  end
14
14
  end
@@ -1,8 +1,11 @@
1
1
  module Konjak
2
2
  class Placeholder < InlineElement
3
3
  # optional attrs
4
- attr_accessor :x, :type, :assoc
4
+ tmx_attr_accessor(:x)
5
+ tmx_attr_accessor(:type)
6
+ tmx_attr_accessor(:assoc)
5
7
 
8
+ # methods
6
9
  def can_contain?(element)
7
10
  CodeData === element || SubFlow === element
8
11
  end
@@ -1,21 +1,18 @@
1
1
  module Konjak
2
2
  class Property < StructuralElement
3
3
  # required attrs
4
- attr_accessor :type
4
+ tmx_attr_accessor(:type, required: true)
5
5
 
6
6
  # optional attrs
7
- attr_accessor :xml_lang, :o_encoding
7
+ tmx_attr_accessor(:xml_lang, :'xml:lang')
8
+ tmx_attr_accessor(:o_encoding, :"o-encoding")
8
9
 
9
- # child
10
- attr_accessor :text
11
-
12
- def initialize(property)
13
- @type = property[:type]
14
- @xml_lang = property['xml:lang']
15
- @o_encoding = property['o-encoding']
16
- @text = Text.new(property.text)
10
+ # childrens
11
+ def text
12
+ Text.new(super)
17
13
  end
18
14
 
15
+ # methods
19
16
  def can_contain?(element)
20
17
  # FIXME
21
18
  # Tool-specific data or text.
@@ -2,12 +2,11 @@ module Konjak
2
2
  # container
3
3
  class Segment < StructuralElement
4
4
  # children
5
- attr_accessor :text
6
-
7
- def initialize(seg)
8
- @text = Text.new(seg.text)
5
+ def text
6
+ Text.new(super)
9
7
  end
10
8
 
9
+ # methods
11
10
  def can_contain?(element)
12
11
  [Text, BeginPairedTag, EndPairedTag, IsolatedTag, Placeholder, Highlight].any? {|c| c === element }
13
12
  end
@@ -1,7 +1,10 @@
1
1
  module Konjak
2
2
  class SubFlow < InlineElement
3
3
  # optional attrs
4
- attr_accessor :data_type, :type
4
+ tmx_attr_accessor(:data_type, :datatype)
5
+ tmx_attr_accessor(:type)
6
+
7
+ #methods
5
8
 
6
9
  # FIXME
7
10
  # Text data,
data/lib/konjak/tmx.rb CHANGED
@@ -1,20 +1,18 @@
1
1
  module Konjak
2
2
  class Tmx < StructuralElement
3
- # required attrs
4
- attr_accessor :version
5
-
6
- def initialize(tmx)
7
- @version = tmx[:version]
8
- # TODO - better error handling
9
- @header, @body = tmx.children
3
+ # required attr
4
+ def version
5
+ root[:version]
10
6
  end
11
7
 
8
+ # required element
12
9
  def header
13
- Header.new @header
10
+ Header.new(root.at_xpath('header'))
14
11
  end
15
12
 
13
+ # required element
16
14
  def body
17
- Body.new @body
15
+ Body.new(root.at_xpath('body'))
18
16
  end
19
17
 
20
18
  # FIXME
@@ -1,33 +1,35 @@
1
1
  module Konjak
2
2
  class TranslationUnit < StructuralElement
3
3
  # optional attrs
4
- attr_accessor :tuid, :o_encoding, :data_type, :usage_count, :last_usage_date
5
- attr_accessor :creation_tool, :creation_tool_version, :creation_date
6
- attr_accessor :creation_id, :change_date, :seg_type, :change_id, :o_tmf
7
- attr_accessor :src_lang
8
-
9
- # children
10
- attr_accessor :variants
11
-
12
- def initialize(tu)
13
- # attrs
14
- @tuid = tu[:tuid]
15
- @data_type = tu[:datatype]
16
- @usage_count = tu[:usagecount]
17
- @last_usage_date = tu[:lastusagedate]
18
- @src_lang = tu[:srclang]
19
-
20
- # children
21
- @variants = tu.children.select {|c| c.name == 'tuv' }.map {|tuv| TranslationUnitVariant.new tuv }
22
- end
23
-
4
+ tmx_attr_accessor(:tuid)
5
+ tmx_attr_accessor(:o_encoding, :"o-encoding")
6
+ tmx_attr_accessor(:data_type, :datatype)
7
+ tmx_attr_accessor(:usage_count, :usagecount)
8
+ tmx_attr_accessor(:last_usage_date, :lastusagedate)
9
+ tmx_attr_accessor(:src_lang, :srclang)
10
+ tmx_attr_accessor(:creation_tool, :creationtool)
11
+ tmx_attr_accessor(:creation_tool_version, :creationtoolversion)
12
+ tmx_attr_accessor(:creation_date, :creationdate)
13
+ tmx_attr_accessor(:creation_id, :creationid)
14
+ tmx_attr_accessor(:change_date, :changedate)
15
+ tmx_attr_accessor(:seg_type, :segtype)
16
+ tmx_attr_accessor(:change_id, :changeid)
17
+ tmx_attr_accessor(:o_tmf, :"o-tmf")
18
+ tmx_attr_accessor(:src_lang, :srclang)
19
+
20
+ # childrens
21
+ def variants
22
+ children.select {|c| c.name == 'tuv' }.map {|tuv| TranslationUnitVariant.new(tuv) }
23
+ end
24
+
25
+ # methods
24
26
  def can_contain?(element)
25
27
  [Note, Property, TranslationUnitVariant].any? {|c| c === element }
26
28
  end
27
29
 
28
30
  # Logically, a complete translation-memory database will contain at least two <tuv> elements in each translation unit.
29
31
  def complete?
30
- child_elements.count {|e| TranslationUnitVariant === e } >= 2
32
+ variants.count >= 2
31
33
  end
32
34
 
33
35
  def has_translation?(src_lang, target_lang)
@@ -50,7 +52,7 @@ module Konjak
50
52
  # Zero, one or more <note>, or <prop> elements in any order, followed by
51
53
  # One or more <tuv> elements.
52
54
  def valid?
53
- child_elements.count {|e| TranslationUnitVariant === e } >= 1
55
+ variants.count >= 1
54
56
  end
55
57
  end
56
58
  end
@@ -1,35 +1,36 @@
1
1
  module Konjak
2
2
  class TranslationUnitVariant < StructuralElement
3
3
  # required attrs
4
- attr_accessor :xml_lang
4
+ tmx_attr_accessor(:xml_lang, :'xml:lang', required: true)
5
5
 
6
6
  # optional attrs
7
- attr_accessor :o_encoding, :data_type, :usage_count, :last_usage_date
8
- attr_accessor :creation_tool, :creation_tool_version, :creation_date
9
- attr_accessor :creation_id, :change_date, :change_id, :o_tmf
7
+ tmx_attr_accessor(:o_encoding, :"o-encoding")
8
+ tmx_attr_accessor(:data_type, :datatype)
9
+ tmx_attr_accessor(:usage_count, :usagecount)
10
+ tmx_attr_accessor(:last_usage_date, :lastusagedate)
11
+ tmx_attr_accessor(:creation_tool, :creationtool)
12
+ tmx_attr_accessor(:creation_tool_version, :creationtoolversion)
13
+ tmx_attr_accessor(:creation_date, :creationdate)
14
+ tmx_attr_accessor(:creation_id, :creationid)
15
+ tmx_attr_accessor(:change_date, :changedate)
16
+ tmx_attr_accessor(:change_id, :changeid)
17
+ tmx_attr_accessor(:o_tmf, :"o-tmf")
10
18
 
11
- # children
12
- attr_accessor :notes, :properties, :segment
19
+ # childrens
20
+ def notes
21
+ children.select {|c| c.name == 'note' }.map {|n| Note.new(n) }
22
+ end
13
23
 
14
- def initialize(tuv)
15
- @xml_lang = tuv['xml:lang']
16
- @o_encoding = tuv['o-encoding']
17
- @data_type = tuv['datatype']
18
- @usage_count = tuv['usagecount']
19
- @last_usage_date = tuv['lastusagedate']
20
- @creation_tool = tuv['creationtool']
21
- @creation_tool_version = tuv['creationtoolversion']
22
- @creation_date = tuv['creationdate']
23
- @creation_id = tuv['creationid']
24
- @change_date = tuv['changedate']
25
- @change_id = tuv['changeid']
26
- @o_tmf = tuv['o-tmf']
24
+ def properties
25
+ children.select {|c| c.name == 'prop' }.map {|n| Property.new(n) }
26
+ end
27
27
 
28
- @notes = tuv.children.select {|c| c.name == 'note' }.map {|n| Note.new n }
29
- @properties = tuv.children.select {|c| c.name == 'prop' }.map {|n| Property.new n }
30
- @segment = Segment.new(tuv.children.detect {|c| c.name == 'seg' })
28
+ def segment
29
+ Segment.new(children.detect {|c| c.name == 'seg' })
31
30
  end
32
31
 
32
+ # methods
33
+
33
34
  # FIXME
34
35
  # Zero, one or more <note>, or <prop> elements in any order, followed by
35
36
  # One <seg> element.
@@ -2,8 +2,9 @@ module Konjak
2
2
  # DEPRECATED
3
3
  class UnknownTag < InlineElement
4
4
  # optional attrs
5
- attr_accessor :x
5
+ tmx_attr_accessor(:x)
6
6
 
7
+ # methods
7
8
  def can_contain?(element)
8
9
  CodeData === element || SubFlow === element
9
10
  end
@@ -1,22 +1,19 @@
1
1
  module Konjak
2
2
  class UserDefinedEncoding < StructuralElement
3
3
  # required attrs
4
- attr_accessor :name
4
+ tmx_attr_accessor(:name, required: true)
5
5
 
6
6
  # FIXME
7
7
  # base (required if one or more of the <map/> elements contains a code attribute).
8
8
  # optional attrs
9
- attr_accessor :base
9
+ tmx_attr_accessor(:base)
10
10
 
11
- # children
12
- attr_accessor :maps
13
-
14
- def initialize(ude)
15
- @name = ude[:name]
16
- @base = ude[:base]
17
- @maps = ude.children.select {|c| c.name == 'map' }.map {|n| Map.new n }
11
+ # childrens
12
+ def maps
13
+ children.select {|c| c.name == 'map' }.map {|n| Map.new(n) }
18
14
  end
19
15
 
16
+ # methods
20
17
  def can_contain?(element)
21
18
  Map === element
22
19
  end
@@ -1,3 +1,3 @@
1
1
  module Konjak
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe Konjak do
4
+ let(:sample_tmx) { File.read('spec/fixtures/sample.tmx') }
5
+
6
+ let(:tmx) { Konjak.parse(sample_tmx) }
7
+
8
+ subject { tmx.to_xml }
9
+
10
+ context 'not modified' do
11
+ it { is_expected.to equal_xml(sample_tmx) }
12
+ end
13
+
14
+ context 'modified' do
15
+ context 'element attribute' do
16
+ before do
17
+ tmx.header.change_id = 'john doe'
18
+ end
19
+
20
+ it { is_expected.not_to equal_xml(sample_tmx) }
21
+
22
+ specify do
23
+ expect(Konjak.parse(subject).header.change_id).to eq 'john doe'
24
+ end
25
+ end
26
+
27
+ context 'segment text' do
28
+ before do
29
+ tu = tmx.body.translation_units.first
30
+ tu.variant('EN').segment.content = 'hello world'
31
+ end
32
+
33
+ it { is_expected.not_to equal_xml(sample_tmx) }
34
+
35
+ specify do
36
+ tu = Konjak.parse(subject).body.translation_units.first
37
+ expect(tu.variant('EN').segment.text).to eq 'hello world'
38
+ end
39
+ end
40
+ end
41
+ end
data/spec/spec_helper.rb CHANGED
@@ -4,5 +4,8 @@ if ENV['CODECLIMATE_REPO_TOKEN']
4
4
  end
5
5
 
6
6
  require 'konjak'
7
+ require 'pry'
7
8
 
8
9
  # spec/fixtures/sample.tmx from http://www.ttt.org/oscarstandards/tmx/#AppSample
10
+
11
+ Dir['spec/support/**/*.rb'].each {|path| load path }
@@ -0,0 +1,14 @@
1
+ require 'rspec/expectations'
2
+
3
+ RSpec::Matchers.define :equal_xml do |expected|
4
+ match do |actual|
5
+ Nokogiri::XML(expected).to_s == Nokogiri::XML(actual).to_s
6
+ end
7
+
8
+ failure_message do |actual|
9
+ actual_xml = Nokogiri::XML(actual).to_s
10
+ expected_xml = Nokogiri::XML(expected).to_s
11
+
12
+ "#{actual_xml}\n\nis not equal\n\n#{expected_xml}"
13
+ end
14
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: konjak
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seiei Higa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-18 00:00:00.000000000 Z
11
+ date: 2015-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mem
@@ -169,12 +169,14 @@ files:
169
169
  - lib/konjak/user_defined_encoding.rb
170
170
  - lib/konjak/version.rb
171
171
  - spec/fixtures/gtt.tmx
172
+ - spec/fixtures/konjak_modify_spec.rb
172
173
  - spec/fixtures/sample.tmx
173
174
  - spec/konjak_parse_spec.rb
174
175
  - spec/konjak_spec.rb
175
176
  - spec/konjak_translate_spec.rb
176
177
  - spec/spec_helper.rb
177
- homepage: https://github.com/hanachin/konjak
178
+ - spec/support/equal_xml_matcher.rb
179
+ homepage: https://github.com/yasslab/konjak
178
180
  licenses:
179
181
  - MIT
180
182
  metadata: {}
@@ -200,9 +202,11 @@ specification_version: 4
200
202
  summary: TMX(Translation Memory exChange) tools for ruby
201
203
  test_files:
202
204
  - spec/fixtures/gtt.tmx
205
+ - spec/fixtures/konjak_modify_spec.rb
203
206
  - spec/fixtures/sample.tmx
204
207
  - spec/konjak_parse_spec.rb
205
208
  - spec/konjak_spec.rb
206
209
  - spec/konjak_translate_spec.rb
207
210
  - spec/spec_helper.rb
211
+ - spec/support/equal_xml_matcher.rb
208
212
  has_rdoc: