embrace 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/embrace/brackets.rb +21 -20
- data/lib/embrace/version.rb +1 -1
- data/lib/embrace.rb +4 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c95bc8f771e08e4ef58fa14e41645a09eda9b45
|
4
|
+
data.tar.gz: 07e95a03836461446da5297a12c7843d338b1ceb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 012075dc5a54d2433ba514ab50ca31a32fee46bbfb699072995276b58c09caf0f4a8db8dafeac8db20cb30b878ff9e340ee624fb8f0e6218a60f98a8054bb077
|
7
|
+
data.tar.gz: 71464d197802977afd6e15548cbd8ff60c4e7756a7839d3201a949b6709149e830dfa2406e1b6b073014ca00e51197be3a2a10078cc8a5bd8d1c6a9d264fc8aa
|
data/lib/embrace/brackets.rb
CHANGED
@@ -1,40 +1,41 @@
|
|
1
1
|
require "embrace"
|
2
2
|
|
3
3
|
module Embrace
|
4
|
-
class Brackets
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
4
|
+
class Brackets < Proc
|
5
|
+
class << self
|
6
|
+
def from_brackets(opening, closing)
|
7
|
+
new do |text|
|
8
|
+
"#{opening}#{text}#{closing}"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def from_str(style)
|
13
|
+
i = style.size / 2
|
14
|
+
from_brackets(style[0...i], style[i..-1])
|
15
|
+
end
|
14
16
|
end
|
15
17
|
|
16
18
|
def to_ary
|
17
|
-
|
19
|
+
bracketed = self["a"]
|
20
|
+
index = bracketed.chars.zip(self["b"].chars).find_index { |a, b| a != b }
|
21
|
+
[ bracketed[0...index], bracketed[(index + 1)..-1] ]
|
18
22
|
end
|
19
23
|
|
20
24
|
alias_method :to_a, :to_ary
|
21
25
|
|
22
|
-
def
|
23
|
-
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.from_str(style)
|
27
|
-
i = style.size / 2
|
28
|
-
new(style[0...i], style[i..-1])
|
26
|
+
def inspect
|
27
|
+
to_a.inspect
|
29
28
|
end
|
30
29
|
end
|
31
30
|
|
32
31
|
module_function
|
33
32
|
|
34
|
-
def Brackets(style)
|
33
|
+
def Brackets(style, *rest)
|
34
|
+
return Brackets.from_brackets(*[ style, *rest ].map(&:to_s)) unless rest.empty?
|
35
|
+
|
35
36
|
case style
|
36
37
|
when Brackets then style
|
37
|
-
when Array then Brackets
|
38
|
+
when Array then Brackets(*style)
|
38
39
|
else
|
39
40
|
Brackets.from_str(style.to_s)
|
40
41
|
end
|
data/lib/embrace/version.rb
CHANGED
data/lib/embrace.rb
CHANGED
@@ -3,9 +3,9 @@ require "embrace/brackets"
|
|
3
3
|
require "embrace/string_methods"
|
4
4
|
|
5
5
|
module Embrace
|
6
|
-
BRACKETS = Brackets
|
7
|
-
PARENTHESES = Brackets
|
8
|
-
BRACES = Brackets
|
6
|
+
BRACKETS = Brackets("[", "]").freeze
|
7
|
+
PARENTHESES = Brackets("(", ")").freeze
|
8
|
+
BRACES = Brackets("{", "}").freeze
|
9
9
|
|
10
10
|
refine String do
|
11
11
|
include StringMethods
|
@@ -14,7 +14,7 @@ module Embrace
|
|
14
14
|
module_function
|
15
15
|
|
16
16
|
def bracket(text, style:, pattern: /\A.*\z/)
|
17
|
-
text.gsub(pattern, &Brackets(style)
|
17
|
+
text.gsub(pattern, &Brackets(style))
|
18
18
|
end
|
19
19
|
|
20
20
|
def bracketer(style:, **options)
|