Module: Embrace

Defined in:
lib/embrace.rb,
lib/embrace/version.rb,
lib/embrace/brackets.rb,
lib/embrace/string_methods.rb

Defined Under Namespace

Modules: StringMethods Classes: Brackets

Constant Summary collapse

BRACKETS =
Brackets("[", "]").freeze
PARENTHESES =
Brackets("(", ")").freeze
BRACES =
Brackets("{", "}").freeze
VERSION =
"1.2.0"

Class Method Summary collapse

Class Method Details

.bracket(text, style:, pattern: /\A.*\z/) ⇒ Object



16
17
18
# File 'lib/embrace.rb', line 16

def bracket(text, style:, pattern: /\A.*\z/)
  text.gsub(pattern, &Brackets(style))
end

.bracketer(style:, **options) ⇒ Object



20
21
22
23
# File 'lib/embrace.rb', line 20

def bracketer(style:, **options)
  brackets = Brackets(style)
  ->(text) { bracket(text, style: brackets, **options)}
end

.Brackets(style, *rest) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/embrace/brackets.rb', line 33

def Brackets(style, *rest)
  return Brackets.from_brackets(*[ style, *rest ].map(&:to_s)) unless rest.empty?

  case style
  when Brackets then style
  when Array    then Brackets(*style)
  else
    Brackets.from_str(style.to_s)
  end
end