rosetta-stone 0.2.1 → 0.2.2

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
  SHA256:
3
- metadata.gz: a533462d58d84278dc028e4045c6eaaa31d85bbc57b0d84b973fc65e77ba9f54
4
- data.tar.gz: ead94d4194d3f3cf9cc09e3fc4e4330ebe9d8b8f502a09ec89d972176fc1d695
3
+ metadata.gz: 5c000b67224ecdf1b44c25b80edf33095de22f75e83458ae19f28f87f34cfe91
4
+ data.tar.gz: 4903ac60987dbdc6540363f3eb0cac96ace899a7590f6fd80ae0ee94889a139d
5
5
  SHA512:
6
- metadata.gz: fab482ccd77877e6b8f9af64c196ef3834840e0263ea3b3bea806f2d7d1613ee64f2029c78efa4e3beec755cbacc19bdf7c28babd631dba54a1b847352003048
7
- data.tar.gz: 1b0f519e1f16a1f980b3ca87a3cc0c041745aba1d26abef3c85320d2a0a68516b60d628cb459950c8639c4633645facb814c9da38c33aa2940d8cd4f27c00f78
6
+ metadata.gz: fd3cfd1efd01650d80c27b150f08cdb428a628da3673f4b3385888030471ee733298d308c554a35e6b5ae9cfa7ee2aa2f27602f844a45723993674a00a311b70
7
+ data.tar.gz: 6c523eeb7466cc2db487e25fbc53ce65b9c38a59747eeaefce28d47e51a1be23363a509a2ca29d200d6ac72c5ded13e1a8d3d86b20be6f95f662edded65322be
data/.gitignore CHANGED
@@ -1,6 +1,7 @@
1
1
  *.swp
2
2
  .ruby-version
3
3
  .byebug_history
4
+ Gemfile.lock
4
5
 
5
6
  pkg/
6
7
  tmp/
data/README.md CHANGED
@@ -26,7 +26,7 @@ Or install it yourself as:
26
26
  The easiest way to use the library is to `require 'rosetta'` first, and then
27
27
  where needed:
28
28
  ```ruby
29
- Rosetta.translate(my_input_text, from: <input_format>, to: <output_format>)`
29
+ Rosetta.translate(my_input_text, from: <input_format>, to: <output_format>)
30
30
  ```
31
31
  Example:
32
32
  ```ruby
@@ -1,19 +1,18 @@
1
1
  require 'rosetta/deserializers'
2
2
  require 'rosetta/exceptions'
3
+ require 'rosetta/support'
3
4
 
4
5
  module Rosetta
5
6
  module Deserializers
6
7
  class Base
8
+ using Rosetta::Support
7
9
  attr_reader :input
8
10
 
9
11
  class << self
10
12
  def inherited(new_serializer)
11
13
  key = new_serializer.name.match(/^(.*?)(Deserializer)?$/)[1]
12
14
  key = key.split("::").last
13
- #NOTE: Similar to Rails's #underscore
14
- #TODO: Extract in refinement?
15
- key = key.scan(/[A-Z]+[a-z]*/).join('_').downcase.to_sym
16
- Deserializers.register(key, new_serializer)
15
+ Deserializers.register(key.underscore.to_sym, new_serializer)
17
16
  end
18
17
 
19
18
  def call(input)
@@ -1,5 +1,6 @@
1
1
  require 'rosetta/serializers'
2
2
  require 'rosetta/exceptions'
3
+ require 'rosetta/support'
3
4
 
4
5
  module Rosetta
5
6
  module Serializers
@@ -7,13 +8,12 @@ module Rosetta
7
8
  attr_reader :elements
8
9
 
9
10
  class << self
11
+ using Rosetta::Support
12
+
10
13
  def inherited(new_serializer)
11
14
  key = new_serializer.name.match(/^(.*?)(Serializer)?$/)[1]
12
15
  key = key.split("::").last
13
- #NOTE: Similar to Rails's #underscore
14
- #TODO: Extract in refinement?
15
- key = key.scan(/[A-Z]+[a-z]*/).join('_').downcase.to_sym
16
- Serializers.register(key, new_serializer)
16
+ Serializers.register(key.underscore.to_sym, new_serializer)
17
17
  end
18
18
 
19
19
  def call(elements)
@@ -1,8 +1,11 @@
1
1
  require 'rosetta/exceptions'
2
+ require 'rosetta/support'
2
3
 
3
4
  module Rosetta
4
5
  module Support
5
6
  module Registerable
7
+ using Rosetta::Support
8
+
6
9
  def registerable_as(nature)
7
10
  @registered = {}
8
11
 
@@ -15,26 +18,19 @@ module Rosetta
15
18
  end
16
19
 
17
20
  define_singleton_method :register do |name, object=nil, &block|
18
- #TODO: Feels clunky, string refinement maybe?
19
- nature_words = nature.to_s.downcase
20
- .split('_')
21
- .map { |word| word[0].upcase + word[1..-1] }
22
-
23
- camel_nature = nature_words.join
24
- human_nature = nature_words.join(' ')
25
-
26
- error_name = :"Existing#{camel_nature}Error"
21
+ nature = nature.to_s
22
+ error_name = :"Existing#{nature.camelize}Error"
27
23
  error_class = if constants.include?(error_name)
28
24
  const_get(error_name)
29
25
  else
30
26
  RegistrationError
31
27
  end
32
28
  raise error_class, <<-ERROR.strip if @registered.key? name
33
- #{human_nature} #{name} is already registered.
29
+ #{nature.titleize} #{name} is already registered.
34
30
  ERROR
35
31
 
36
32
  if object && block
37
- raise ArgumentError, "Can't take both #{human_nature.downcase} object and block."
33
+ raise ArgumentError, "Can't take both #{nature.downcase} object and block."
38
34
  end
39
35
  @registered[name] = object || block
40
36
  end
@@ -0,0 +1,34 @@
1
+ module Rosetta
2
+ module Support
3
+ refine String do
4
+ def underscore
5
+ case_components.map(&:downcase).join('_')
6
+ end
7
+
8
+ def camelize
9
+ case_components.map(&:capitalize).join
10
+ end
11
+
12
+ def titleize
13
+ case_components.map(&:capitalize).join(' ')
14
+ end
15
+
16
+ def capitalize
17
+ self[0].upcase + self[1..-1].downcase
18
+ end
19
+
20
+ def case_components
21
+ full_caps_word = "[A-Z0-9]+(?![a-z])"
22
+ titlecase_word = "[A-Z0-9][a-z0-9]*"
23
+ lowercase_word = "(?!<[A-Z0-9])[a-z0-9]*"
24
+ separator = "[\w_-]"
25
+ word = "(#{full_caps_word})|(#{titlecase_word}|(#{lowercase_word})"
26
+ components = self.scan(/(?:#{word})#{separator}?)/)
27
+
28
+ # HACK: Removing scan weirdness... there's probably a better way to do
29
+ # this. Maybe stringscanner ?
30
+ components.map { |component| component.reject { |e| e == '' || e.nil? }.uniq }.flatten
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,6 @@
1
+ require 'rosetta/support/string_refinement'
2
+
3
+ module Rosetta
4
+ module Support
5
+ end
6
+ end
@@ -1,3 +1,3 @@
1
1
  module Rosetta
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rosetta-stone
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jérémie Bonal
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-08-03 00:00:00.000000000 Z
11
+ date: 2019-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug
@@ -78,7 +78,6 @@ files:
78
78
  - ".travis.yml"
79
79
  - CODE_OF_CONDUCT.md
80
80
  - Gemfile
81
- - Gemfile.lock
82
81
  - LICENSE.txt
83
82
  - README.md
84
83
  - Rakefile
@@ -93,7 +92,9 @@ files:
93
92
  - lib/rosetta/serializers.rb
94
93
  - lib/rosetta/serializers/base.rb
95
94
  - lib/rosetta/serializers/csv.rb
95
+ - lib/rosetta/support.rb
96
96
  - lib/rosetta/support/registerable.rb
97
+ - lib/rosetta/support/string_refinement.rb
97
98
  - lib/rosetta/translation.rb
98
99
  - lib/rosetta/version.rb
99
100
  - rosetta.gemspec
data/Gemfile.lock DELETED
@@ -1,37 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- rosetta-stone (0.2.1)
5
-
6
- GEM
7
- remote: https://rubygems.org/
8
- specs:
9
- byebug (11.0.1)
10
- diff-lcs (1.3)
11
- rake (10.5.0)
12
- rspec (3.8.0)
13
- rspec-core (~> 3.8.0)
14
- rspec-expectations (~> 3.8.0)
15
- rspec-mocks (~> 3.8.0)
16
- rspec-core (3.8.2)
17
- rspec-support (~> 3.8.0)
18
- rspec-expectations (3.8.4)
19
- diff-lcs (>= 1.2.0, < 2.0)
20
- rspec-support (~> 3.8.0)
21
- rspec-mocks (3.8.1)
22
- diff-lcs (>= 1.2.0, < 2.0)
23
- rspec-support (~> 3.8.0)
24
- rspec-support (3.8.2)
25
-
26
- PLATFORMS
27
- ruby
28
-
29
- DEPENDENCIES
30
- bundler (~> 2.0)
31
- byebug
32
- rake (~> 10.0)
33
- rosetta-stone!
34
- rspec (~> 3.0)
35
-
36
- BUNDLED WITH
37
- 2.0.1