Module: BRB::Sigil

Defined in:
lib/brb.rb

Class Method Summary collapse

Class Method Details

.namesObject



19
# File 'lib/brb.rb', line 19

def self.names = @values.keys

.register(key, replacer) ⇒ Object



45
46
47
# File 'lib/brb.rb', line 45

def self.register(key, replacer)
  @values[key.to_s] = replacer
end

.replace(scanner, key) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/brb.rb', line 22

def self.replace(scanner, key)
  @values.fetch(key).then do |template|
    case
    when key == "t" && scanner.scan(/\.[\.\w]+/) then template.sub ":value", scanner.matched
    when scanner.check(/\(/) then template.sub ":value", scan_arguments(scanner)
    else
      template
    end
  end
end

.scan_arguments(scanner) ⇒ Object



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

def self.scan_arguments(scanner)
  arguments, open_parens = +"", 0

  begin
    arguments << scanner.scan_until(/\(|\)/)
    open_parens += arguments.last == "(" ? 1 : -1
  end until open_parens.zero?

  arguments[1..-2]
end