Module: Embrace

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

Defined Under Namespace

Modules: Brackets, StringMethods

Constant Summary collapse

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

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_or_opening, *closing) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/embrace/brackets.rb', line 19

def Brackets(style_or_opening, *closing)
  return Brackets.from_brackets(style_or_opening, *closing) unless closing.empty?

  case style_or_opening
  when Proc  then style_or_opening
  when Array then Brackets.from_brackets(*style_or_opening)
  else
    Brackets.from_str(style_or_opening.to_s)
  end
end