embrace 0.1.0 → 0.2.0

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: 7cf16a531820bd4981607a77ee08aa5fbb880772
4
- data.tar.gz: 7cb3897ff764597adc0017bd74e12d6f9e89fcab
3
+ metadata.gz: b7a68687b49b752093867e4dceebd1500a7eb02d
4
+ data.tar.gz: f0117298d06412edda85916b9306d78fe203543d
5
5
  SHA512:
6
- metadata.gz: aca5bc262f6c6f00c8026c48adf95a57c71723fd9eb85cbcb8549ee5073a5a972ada747a67a7a713735fab9b5c08462ad12320b27ea3caf2cd53e78d79fdf8c3
7
- data.tar.gz: d7f81ffc22bef52768178e0c857f8c56dcee29971da691002a486072cd1a16adb1de38505fb9e2ae68b617f494e3994c024b8a0c6c0aea7b05123509b0159026
6
+ metadata.gz: fed4641a0817635b2f1f817805104e38ef082261d1ae5ce9e4a5aa9c4d1b41e7de7e4e7d01eade8b14339d116992329866197a8908afd45d2ccb4cfc3c140178
7
+ data.tar.gz: 69248b4b2cbfb302ca889c840bdfd9682c3d83e565f9c378158405427266e21ed280c60e39eda9812c22bf9d65d255b424541363896e8a251ae9417c71ede4ad
@@ -2,31 +2,20 @@ require "embrace"
2
2
 
3
3
  module Embrace
4
4
  module Brackets
5
- BRACKET_STYLES = Hash.new { |_, k| k }.merge({
6
- "(" => ")",
7
- "{" => "}",
8
- "[" => "]",
9
- "<" => ">"
10
- }).freeze
5
+ module_function
11
6
 
12
- module StringMethods
13
- def bracket(*style)
14
- Brackets.wrap(self, *style)
15
- end
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
- refine String do
19
- include StringMethods
20
- end
14
+ module_function
21
15
 
22
- module_function
16
+ def Brackets(style)
17
+ return style.to_ary if style.respond_to? :to_ary
23
18
 
24
- def wrap(text, style = "(")
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
@@ -1,3 +1,3 @@
1
1
  module Embrace
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
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
- module StringMethods
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
- def wrap(text, before, after)
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.1.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 00:00:00.000000000 Z
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: