Class: Wp2txt::ParserFunctions

Inherits:
Object
  • Object
show all
Defined in:
lib/wp2txt/parser_functions.rb

Overview

Evaluates MediaWiki parser functions Handles #if, #ifeq, #switch, #expr, #ifexpr, and string functions

Constant Summary collapse

MONTH_NAMES =
%w[
  January February March April May June
  July August September October November December
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(reference_date: nil, preserve_unknown: false) ⇒ ParserFunctions

Returns a new instance of ParserFunctions.



14
15
16
17
# File 'lib/wp2txt/parser_functions.rb', line 14

def initialize(reference_date: nil, preserve_unknown: false)
  @reference_date = reference_date || Time.now
  @preserve_unknown = preserve_unknown
end

Instance Method Details

#evaluate(text) ⇒ Object

Main evaluation method



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

def evaluate(text)
  return text if text.nil? || text.empty?

  # Early exit: no parser functions to evaluate
  return text unless text.include?("{{#")

  result = text.dup

  # Process parser functions from innermost to outermost
  max_iterations = 10
  iteration = 0

  while result.include?("{{#") && iteration < max_iterations
    previous = result.dup
    result = evaluate_single_pass(result)
    break if result == previous
    iteration += 1
  end

  result
end