Method: HookApp#validate_format

Defined in:
lib/hook/hookapp.rb

#validate_format(fmt, options) ⇒ Object

Check if format fully matches or matches the first character of available options. Return full valid format or nil



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/hook/hookapp.rb', line 20

def validate_format(fmt, options)
  valid_format_rx = options.map { |format| format.sub(/^(.)(.*)$/, '^\1(\2)?$') }
  valid_format = nil
  valid_format_rx.each_with_index do |rx, i|
    cmp = Regexp.new(rx, 'i')
    next unless fmt =~ cmp

    valid_format = options[i]
    break
  end
  valid_format
end