embrace 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -5
- data/lib/embrace/brackets.rb +29 -7
- data/lib/embrace/string_methods.rb +3 -3
- data/lib/embrace/version.rb +1 -1
- data/lib/embrace.rb +5 -2
- 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: a44011000a9416a96d2efd8be38b4570d3954ae4
|
4
|
+
data.tar.gz: 74002464e5315a25257c3645e2afbea79e23c3e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6bb8a6fbf3c5908e3d07767bfde1e62940b9744fd90ca35d1cff1b743580b4222c956c48e3f872ad1b9fb7e971fc8f1bbf42f957bcc6661e276e582fdf5bc66d
|
7
|
+
data.tar.gz: 52011de09465cf9706ba7e6ddf7dc87ed65b7dbf105eb69acc29208b10e246ffabfa22896fa24290c575066b4f128bf02043d583bfdac7897b2c4b431d90d798
|
data/README.md
CHANGED
@@ -4,9 +4,8 @@
|
|
4
4
|
[![Build status][build-badge]][build]
|
5
5
|
[![Coverage Status][coverage-badge]][coverage]
|
6
6
|
|
7
|
-
Embrace is a
|
8
|
-
bracketing styles
|
9
|
-
strings.
|
7
|
+
Embrace is a simple library for bracketing strings, or parts of strings. While it focuses on three common
|
8
|
+
bracketing styles, you can use custom styles, or even wrap text in arbitrary strings.
|
10
9
|
|
11
10
|
## Usage
|
12
11
|
|
@@ -74,7 +73,7 @@ If you need to wrap text in asymmetrical strings, then you can supply an array a
|
|
74
73
|
"the quick brown fox.".bracket(style: %w{ beginning> <end }) # => "beginning>the quick brown fox.<end"
|
75
74
|
```
|
76
75
|
|
77
|
-
Note that only the first two elements of the array will be
|
76
|
+
Note that only the first two elements of the array will be used.
|
78
77
|
|
79
78
|
### Module function
|
80
79
|
|
@@ -120,7 +119,7 @@ version, push git commits and tags, and push the `.gem` file to [rubygems.org](h
|
|
120
119
|
|
121
120
|
## Contributing
|
122
121
|
|
123
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
122
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/johncarney/embrace. This project is
|
124
123
|
intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the
|
125
124
|
[Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
126
125
|
|
data/lib/embrace/brackets.rb
CHANGED
@@ -1,20 +1,42 @@
|
|
1
1
|
require "embrace"
|
2
2
|
|
3
3
|
module Embrace
|
4
|
-
|
5
|
-
|
4
|
+
class Brackets
|
5
|
+
attr_reader :opening, :closing
|
6
6
|
|
7
|
-
def
|
7
|
+
def initialize(opening, closing)
|
8
|
+
@opening = opening
|
9
|
+
@closing = closing
|
10
|
+
end
|
11
|
+
|
12
|
+
def around(text)
|
13
|
+
"#{opening}#{text}#{closing}"
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_ary
|
17
|
+
[ opening, closing ]
|
18
|
+
end
|
19
|
+
|
20
|
+
alias_method :to_a, :to_ary
|
21
|
+
|
22
|
+
def to_s
|
23
|
+
"#{opening}#{closing}"
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.from_str(style)
|
8
27
|
i = style.size / 2
|
9
|
-
|
28
|
+
new(style[0...i], style[i..-1])
|
10
29
|
end
|
11
30
|
end
|
12
31
|
|
13
32
|
module_function
|
14
33
|
|
15
34
|
def Brackets(style)
|
16
|
-
|
17
|
-
|
18
|
-
Brackets.
|
35
|
+
case style
|
36
|
+
when Brackets then style
|
37
|
+
when Array then Brackets.new(*style)
|
38
|
+
else
|
39
|
+
Brackets.from_str(style.to_s)
|
40
|
+
end
|
19
41
|
end
|
20
42
|
end
|
@@ -1,14 +1,14 @@
|
|
1
1
|
module Embrace
|
2
2
|
module StringMethods
|
3
|
-
def bracket(style:
|
3
|
+
def bracket(style: BRACKETS, **options)
|
4
4
|
Embrace.bracket(self, style: style, **options)
|
5
5
|
end
|
6
6
|
|
7
|
-
def parenthesize(style:
|
7
|
+
def parenthesize(style: PARENTHESES, **options)
|
8
8
|
Embrace.bracket(self, style: style, **options)
|
9
9
|
end
|
10
10
|
|
11
|
-
def brace(style:
|
11
|
+
def brace(style: BRACES, **options)
|
12
12
|
Embrace.bracket(self, style: style, **options)
|
13
13
|
end
|
14
14
|
end
|
data/lib/embrace/version.rb
CHANGED
data/lib/embrace.rb
CHANGED
@@ -3,6 +3,10 @@ require "embrace/brackets"
|
|
3
3
|
require "embrace/string_methods"
|
4
4
|
|
5
5
|
module Embrace
|
6
|
+
BRACKETS = Brackets.new("[", "]").freeze
|
7
|
+
PARENTHESES = Brackets.new("(", ")").freeze
|
8
|
+
BRACES = Brackets.new("{", "}").freeze
|
9
|
+
|
6
10
|
refine String do
|
7
11
|
include StringMethods
|
8
12
|
end
|
@@ -10,8 +14,7 @@ module Embrace
|
|
10
14
|
module_function
|
11
15
|
|
12
16
|
def bracket(text, style:, pattern: /\A.*\z/)
|
13
|
-
|
14
|
-
text.gsub(pattern, "#{opening}\\0#{closing}")
|
17
|
+
text.gsub(pattern, &Brackets(style).method(:around))
|
15
18
|
end
|
16
19
|
|
17
20
|
def bracketer(style:, **options)
|