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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 75b37f0f9a63be6227d517a43fd646e59be725d9
4
- data.tar.gz: 626f977a239048160e1ed9494d37e6933f4e3c54
3
+ metadata.gz: a44011000a9416a96d2efd8be38b4570d3954ae4
4
+ data.tar.gz: 74002464e5315a25257c3645e2afbea79e23c3e5
5
5
  SHA512:
6
- metadata.gz: 8fbc5529b32346338814f34d0ea9cb4dc18c7d44ed41439e5ada2e1ee4524326cbbfab191ea2b4b247e2cf2ff53d7000b4d0b08825c9de83392364b8fd5e902d
7
- data.tar.gz: a6ff5d1f94a1d09c49be21cf218d170407444e2c79bd5948fcf72d6e780fed00d6515e4923199dee15d09a526413f0a8a60e16b46cf89f8426d12a5070de0eab
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 simply library for bracketing strings, or parts of strings. While it focuses on common
8
- bracketing styles - `()`, `[]`, and `{}` - you can use custom styles, and even wrap text in arbitrary
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 use.
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/[USERNAME]/embrace. This project is
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
 
@@ -1,20 +1,42 @@
1
1
  require "embrace"
2
2
 
3
3
  module Embrace
4
- module Brackets
5
- module_function
4
+ class Brackets
5
+ attr_reader :opening, :closing
6
6
 
7
- def split(style)
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
- [ style[0...i], style[i..-1] ]
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
- return style.to_ary if style.respond_to? :to_ary
17
-
18
- Brackets.split(style.to_s)
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: "[]", **options)
3
+ def bracket(style: BRACKETS, **options)
4
4
  Embrace.bracket(self, style: style, **options)
5
5
  end
6
6
 
7
- def parenthesize(style: "()", **options)
7
+ def parenthesize(style: PARENTHESES, **options)
8
8
  Embrace.bracket(self, style: style, **options)
9
9
  end
10
10
 
11
- def brace(style: "{}", **options)
11
+ def brace(style: BRACES, **options)
12
12
  Embrace.bracket(self, style: style, **options)
13
13
  end
14
14
  end
@@ -1,3 +1,3 @@
1
1
  module Embrace
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
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
- opening, closing = Brackets(style)
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)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embrace
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Carney