class Fop::Compiler::Instructions::ExpressionMatch
Public Class Methods
new(node)
click to toggle source
# File lib/fop/compiler.rb, line 42 def initialize(node) @regex = node.regex&.regex @op = node.operator_token ? OPERATIONS.fetch(node.operator_token.val) : nil @regex_match = node.regex_match @args = node.args&.map { |arg| arg.has_captures ? arg.segments : arg.segments.join("") } end
Public Instance Methods
call(input)
click to toggle source
# File lib/fop/compiler.rb, line 51 def call(input) if (match = @regex.match(input)) val = match.to_s blank = val == BLANK input.sub!(val, BLANK) unless blank found_val = @regex_match || !blank if @op and @args and found_val args = @args.map { |arg| case arg when String then arg when Array then sub_caps(arg, match.captures) else raise "Unexpected arg type #{arg.class.name}" end } @op.proc.call(val, args) else val end end end
Private Instance Methods
sub_caps(args, caps)
click to toggle source
# File lib/fop/compiler.rb, line 74 def sub_caps(args, caps) args.map { |a| a.is_a?(Integer) ? caps[a].to_s : a }.join("") end