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.2"

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



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

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

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