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 +4 -4
- data/.gitignore +1 -0
- data/README.md +1 -1
- data/lib/rosetta/deserializers/base.rb +3 -4
- data/lib/rosetta/serializers/base.rb +4 -4
- data/lib/rosetta/support/registerable.rb +7 -11
- data/lib/rosetta/support/string_refinement.rb +34 -0
- data/lib/rosetta/support.rb +6 -0
- data/lib/rosetta/version.rb +1 -1
- metadata +4 -3
- data/Gemfile.lock +0 -37
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c000b67224ecdf1b44c25b80edf33095de22f75e83458ae19f28f87f34cfe91
|
4
|
+
data.tar.gz: 4903ac60987dbdc6540363f3eb0cac96ace899a7590f6fd80ae0ee94889a139d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd3cfd1efd01650d80c27b150f08cdb428a628da3673f4b3385888030471ee733298d308c554a35e6b5ae9cfa7ee2aa2f27602f844a45723993674a00a311b70
|
7
|
+
data.tar.gz: 6c523eeb7466cc2db487e25fbc53ce65b9c38a59747eeaefce28d47e51a1be23363a509a2ca29d200d6ac72c5ded13e1a8d3d86b20be6f95f662edded65322be
|
data/.gitignore
CHANGED
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
|
-
|
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
|
-
|
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
|
-
|
19
|
-
|
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
|
-
#{
|
29
|
+
#{nature.titleize} #{name} is already registered.
|
34
30
|
ERROR
|
35
31
|
|
36
32
|
if object && block
|
37
|
-
raise ArgumentError, "Can't take both #{
|
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
|
data/lib/rosetta/version.rb
CHANGED
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.
|
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-
|
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
|