Method: FormatEngine::FormatSet#initialize

Defined in:
lib/format_engine/format_spec/set.rb

#initialize(format) ⇒ FormatSet

Setup a variable format specification.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/format_engine/format_spec/set.rb', line 21

def initialize(format)
  @raw = format

  if (match_data = /(\d+,)?(\d+)(?=\[)/.match(format))
    qualifier   = "{#{match_data[1] || "1,"}#{match_data[2]}}"
    @short_name = match_data.pre_match + "["
    @long_name  = match_data.pre_match + match_data.post_match
    set         = match_data.post_match
  elsif format =~ /\[/
    qualifier   = "+"
    @short_name = $PREMATCH + $MATCH
    @long_name  = format
    set         = $MATCH + $POSTMATCH
  else
    fail "Invalid set string #{format}"
  end

  @regex = Regexp.new("#{set}#{qualifier}")
end