yaml-translator 0.8.2 → 0.8.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: 0d076ea46fb1b164013c237fe69d471f175ff5f8
4
- data.tar.gz: fc4419c8af60700a7b5c5f376f6e55996bea458c
3
+ metadata.gz: fd1e5419f516c0e5808b709d17ebaf9571b952e2
4
+ data.tar.gz: b049be4c6a92d7ef6892f79f760e249550170b54
5
5
  SHA512:
6
- metadata.gz: e54f86d2255a306818b61b9e58690afca50282cd5f257b2c18665caa1335fde3d1742becb77de6b7ef92b0909f7141cd0e39645e5e4c210be56be5d1ef98ef82
7
- data.tar.gz: d80d766b17844ce696108aeb9ab4a4aab07505315b88b91f64c3aa7acc0c542848e255f1678644b3b8faae10f9741dce782438dbb58ac560e5e3518eb03d204e
6
+ metadata.gz: 5e2719bbd14f5ed9266aac27ea12b129447750c6bbcdbf4d35237bba1bc0111cf3a759b6d3d60ba4a72f61a9e927461075b16ae1cbbda4a01a5a024f53f1ebb7
7
+ data.tar.gz: aab388c974f11d9962ebc53e2545839ff580371a7e4ebd9289624e97f3ff4851e70423d4b246c86dc0fd69090ddd5afd57ba1372028c5b73e6c80f6eed7550f9
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- yaml-translator (0.8.2)
4
+ yaml-translator (0.8.3)
5
5
  diff-lcs
6
6
  easy_translate
7
7
 
@@ -1,6 +1,13 @@
1
1
  module YamlTranslator
2
2
  module Adapters
3
3
  class BaseAdapter
4
+ attr_reader :name
5
+
6
+ def initialize(options={})
7
+ @name = adapter_name
8
+ @options = options
9
+ end
10
+
4
11
  def translate(values, options={})
5
12
  raise 'Translation processing is not implemented'
6
13
  end
@@ -8,6 +15,18 @@ module YamlTranslator
8
15
  def default_options
9
16
  { to: :en }
10
17
  end
18
+
19
+ private
20
+
21
+ def adapter_name
22
+ ptn = /[A-Z\s]*[^A-Z]*/
23
+ class_name = self.class.name.split('::').last
24
+ snake_case_s = class_name.gsub(/Adapter/, '').scan(ptn)
25
+ .map { |v| v.empty? ? nil : v.downcase }
26
+ .compact
27
+ .join('_')
28
+ snake_case_s.to_sym
29
+ end
11
30
  end
12
31
  end
13
32
  end
@@ -3,9 +3,6 @@ require 'easy_translate'
3
3
  module YamlTranslator
4
4
  module Adapters
5
5
  class GoogleTranslateAdapter < BaseAdapter
6
- def initialize(options={})
7
- @options = options
8
- end
9
6
  def translate(values, options={})
10
7
  keys = []
11
8
  texts = []
@@ -2,11 +2,14 @@ require "yaml-translator/adapters"
2
2
 
3
3
  module YamlTranslator
4
4
  class Translator
5
-
6
5
  def initialize(adapter = Adapters::NoopAdapter.new)
7
6
  @adapter = adapter
8
7
  end
9
8
 
9
+ def adapter_name
10
+ @adapter.name
11
+ end
12
+
10
13
  # Translate target
11
14
  #
12
15
  # @param [Locale] locale of translate target
@@ -1,3 +1,3 @@
1
1
  module YamlTranslator
2
- VERSION = '0.8.2'
2
+ VERSION = '0.8.3'
3
3
  end
@@ -2,9 +2,19 @@ require 'rspec/temp_dir'
2
2
 
3
3
  describe YamlTranslator do
4
4
  describe '#create' do
5
- it 'should be load translator' do
6
- translator = YamlTranslator.create(:google_translate, api_key: 'xyz')
7
- expect(translator).to be_kind_of(YamlTranslator::Translator)
5
+ context 'when google translate adapter' do
6
+ it 'should be load translator' do
7
+ translator = YamlTranslator.create(:google_translate, api_key: 'xyz')
8
+ expect(translator).to be_kind_of(YamlTranslator::Translator)
9
+ expect(translator.adapter_name).to eq(:google_translate)
10
+ end
11
+ end
12
+ context 'when noop adapter' do
13
+ it 'should be load translator' do
14
+ translator = YamlTranslator.create(:noop)
15
+ expect(translator).to be_kind_of(YamlTranslator::Translator)
16
+ expect(translator.adapter_name).to eq(:noop)
17
+ end
8
18
  end
9
19
  end
10
20
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yaml-translator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.2
4
+ version: 0.8.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Noritaka Horio
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-08 00:00:00.000000000 Z
11
+ date: 2017-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: easy_translate