Class: HexaPDF::Type::AcroForm::JavaScriptActions::SimplifiedFieldNotationParser
- Inherits:
-
Object
- Object
- HexaPDF::Type::AcroForm::JavaScriptActions::SimplifiedFieldNotationParser
- Defined in:
- lib/hexapdf/type/acro_form/java_script_actions.rb
Overview
Implements a parser for the simplified field notation used for calculating field values.
This notation is used if the predefined functions are too simple but the calculation can still be done by simple arithmetic.
Defined Under Namespace
Classes: ParseError
Instance Method Summary collapse
-
#initialize(form, sfn_string) ⇒ SimplifiedFieldNotationParser
constructor
Creates a new instance for the given AcroForm
form
instance and simplified field notation stringsfn_string
. -
#parse(operations = :calculate) ⇒ Object
Parses the string holding the simplified field notation.
Constructor Details
#initialize(form, sfn_string) ⇒ SimplifiedFieldNotationParser
Creates a new instance for the given AcroForm form
instance and simplified field notation string sfn_string
.
89 90 91 92 |
# File 'lib/hexapdf/type/acro_form/java_script_actions.rb', line 89 def initialize(form, sfn_string) @form = form @tokens = sfn_string.scan(/\p{Alpha}[^()*\/+-]*|\d+(?:[.,]\d*)?|[()*\/+-]/) end |
Instance Method Details
#parse(operations = :calculate) ⇒ Object
Parses the string holding the simplified field notation.
If operations
is :calculate, the calculation is performed and the result returned. If operations
is :generate, a JavaScript representation is generated and returned.
+nil+ is returned regardless of the +operations+ value if there was any problem.
100 101 102 103 104 105 106 |
# File 'lib/hexapdf/type/acro_form/java_script_actions.rb', line 100 def parse(operations = :calculate) operations = (operations == :calculate ? CALCULATE_OPERATIONS : JS_GENERATE_OPERATIONS) result = expression(operations) @tokens.empty? ? result : nil rescue ParseError nil end |