embrace 0.1.0 → 0.2.0
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 +4 -4
- data/lib/embrace/brackets.rb +10 -21
- data/lib/embrace/string_methods.rb +19 -0
- data/lib/embrace/version.rb +1 -1
- data/lib/embrace.rb +54 -7
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b7a68687b49b752093867e4dceebd1500a7eb02d
|
4
|
+
data.tar.gz: f0117298d06412edda85916b9306d78fe203543d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fed4641a0817635b2f1f817805104e38ef082261d1ae5ce9e4a5aa9c4d1b41e7de7e4e7d01eade8b14339d116992329866197a8908afd45d2ccb4cfc3c140178
|
7
|
+
data.tar.gz: 69248b4b2cbfb302ca889c840bdfd9682c3d83e565f9c378158405427266e21ed280c60e39eda9812c22bf9d65d255b424541363896e8a251ae9417c71ede4ad
|
data/lib/embrace/brackets.rb
CHANGED
@@ -2,31 +2,20 @@ require "embrace"
|
|
2
2
|
|
3
3
|
module Embrace
|
4
4
|
module Brackets
|
5
|
-
|
6
|
-
"(" => ")",
|
7
|
-
"{" => "}",
|
8
|
-
"[" => "]",
|
9
|
-
"<" => ">"
|
10
|
-
}).freeze
|
5
|
+
module_function
|
11
6
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
7
|
+
def split(style)
|
8
|
+
i = style.size / 2
|
9
|
+
j = style.size - i
|
10
|
+
[ style[0...i], style[j..-1] ]
|
16
11
|
end
|
12
|
+
end
|
17
13
|
|
18
|
-
|
19
|
-
include StringMethods
|
20
|
-
end
|
14
|
+
module_function
|
21
15
|
|
22
|
-
|
16
|
+
def Brackets(style)
|
17
|
+
return style.to_ary if style.respond_to? :to_ary
|
23
18
|
|
24
|
-
|
25
|
-
Embrace.wrap(text, style, BRACKET_STYLES[style.to_s])
|
26
|
-
end
|
27
|
-
|
28
|
-
def wrapper(*style)
|
29
|
-
->(text) { wrap(text, *style) }
|
30
|
-
end
|
19
|
+
Brackets.split(style.to_s)
|
31
20
|
end
|
32
21
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Embrace
|
2
|
+
module StringMethods
|
3
|
+
def wrap(*with)
|
4
|
+
Embrace.wrap(self, *with)
|
5
|
+
end
|
6
|
+
|
7
|
+
def bracket(style: "[]")
|
8
|
+
Embrace.bracket(self, style: style)
|
9
|
+
end
|
10
|
+
|
11
|
+
def parenthesize(style: "()")
|
12
|
+
Embrace.bracket(self, style: style)
|
13
|
+
end
|
14
|
+
|
15
|
+
def brace(style: "{}")
|
16
|
+
Embrace.bracket(self, style: style)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/embrace/version.rb
CHANGED
data/lib/embrace.rb
CHANGED
@@ -1,12 +1,9 @@
|
|
1
1
|
require "embrace/version"
|
2
2
|
require "embrace/brackets"
|
3
|
+
require "embrace/string_methods"
|
3
4
|
|
4
5
|
module Embrace
|
5
|
-
|
6
|
-
def embrace(*with)
|
7
|
-
Embrace.wrap(self, *with)
|
8
|
-
end
|
9
|
-
end
|
6
|
+
using Brackets
|
10
7
|
|
11
8
|
refine String do
|
12
9
|
include StringMethods
|
@@ -14,13 +11,63 @@ module Embrace
|
|
14
11
|
|
15
12
|
module_function
|
16
13
|
|
17
|
-
|
18
|
-
return unless text
|
14
|
+
# wrap
|
19
15
|
|
16
|
+
def wrap(text, before, after)
|
20
17
|
"#{before}#{text}#{after}"
|
21
18
|
end
|
22
19
|
|
20
|
+
def wrap_if(text, *with, &test)
|
21
|
+
return text unless test.yield text
|
22
|
+
|
23
|
+
wrap(text, *with)
|
24
|
+
end
|
25
|
+
|
26
|
+
def wrap_unless(text, *with, &test)
|
27
|
+
return text if test.yield text
|
28
|
+
|
29
|
+
wrap(text, *with)
|
30
|
+
end
|
31
|
+
|
32
|
+
# wrapper
|
33
|
+
|
23
34
|
def wrapper(*with)
|
24
35
|
->(text) { wrap(text, *with) }
|
25
36
|
end
|
37
|
+
|
38
|
+
def if_wrapper(*with, &test)
|
39
|
+
->(text) { wrap_if(text, *with, &test) }
|
40
|
+
end
|
41
|
+
|
42
|
+
def unless_wrapper(*with, &test)
|
43
|
+
->(text) { wrap_unless(text, *with, &test) }
|
44
|
+
end
|
45
|
+
|
46
|
+
# bracket
|
47
|
+
|
48
|
+
def bracket(text, style:)
|
49
|
+
wrap(text, *Brackets(style))
|
50
|
+
end
|
51
|
+
|
52
|
+
def bracket_if(text, style:, &test)
|
53
|
+
wrap_if(text, *Brackets(style), &test)
|
54
|
+
end
|
55
|
+
|
56
|
+
def bracket_unless(text, style:, &test)
|
57
|
+
wrap_unless(text, *Brackets(style), &test)
|
58
|
+
end
|
59
|
+
|
60
|
+
# bracketer
|
61
|
+
|
62
|
+
def bracketer(style:)
|
63
|
+
wrapper(*Brackets(style))
|
64
|
+
end
|
65
|
+
|
66
|
+
def if_bracketer(style:, &test)
|
67
|
+
if_wrapper(*Brackets(style), &test)
|
68
|
+
end
|
69
|
+
|
70
|
+
def unless_bracketer(style:, &test)
|
71
|
+
unless_wrapper(*Brackets(style), &test)
|
72
|
+
end
|
26
73
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: embrace
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Carney
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -73,6 +73,7 @@ files:
|
|
73
73
|
- embrace.gemspec
|
74
74
|
- lib/embrace.rb
|
75
75
|
- lib/embrace/brackets.rb
|
76
|
+
- lib/embrace/string_methods.rb
|
76
77
|
- lib/embrace/version.rb
|
77
78
|
homepage: https://github.com/johncarney/embrace
|
78
79
|
licenses:
|