class FormatEngine::FormatRgx
A format engine set specification.
Attributes
long_name[R]
The full name of the set.
regex[R]
The regular expression part of this set specification.
short_name[R]
The short form name of the set.
Public Class Methods
new(format)
click to toggle source
Setup a variable format specification.
# File lib/format_engine/format_spec/rgx.rb, line 21 def initialize(format) @long_name = format pre, _, post = format.partition('/') @short_name = pre + '/' exp, _, options = post.partition(/(?<=[^\\])\// ) opt = (options.include?('x') ? Regexp::EXTENDED : 0) | (options.include?('i') ? Regexp::IGNORECASE : 0) | (options.include?('m') ? Regexp::MULTILINE : 0) @regex = Regexp.new(exp.gsub(/\\\//, '/'), opt) end
Public Instance Methods
do_format(spec_info)
click to toggle source
Format onto the output string
# File lib/format_engine/format_spec/rgx.rb, line 42 def do_format(spec_info) fail "The tag %{@raw} may not be used in formatting." end
do_parse(spec_info)
click to toggle source
Parse from the input string
# File lib/format_engine/format_spec/rgx.rb, line 47 def do_parse(spec_info) spec_info.instance_exec(&@block) end
inspect()
click to toggle source
Inspect for debugging.
# File lib/format_engine/format_spec/rgx.rb, line 52 def inspect "Regex(#{@long_name.inspect}, #{@short_name.inspect}, #{regex.inspect})" end
validate(engine)
click to toggle source
Is this format item supported by the engine's library?
# File lib/format_engine/format_spec/rgx.rb, line 35 def validate(engine) @block = engine[@long_name] || engine[@short_name] fail "Unsupported tag = #{@raw.inspect}" unless @block true end
width()
click to toggle source
The width parameter. Handled internally so this is always zero.
# File lib/format_engine/format_spec/rgx.rb, line 16 def width 0 end