Class: Mathematical
- Inherits:
-
Object
- Object
- Mathematical
- Includes:
- Corrections, Validator
- Defined in:
- lib/mathematical.rb,
lib/mathematical/version.rb,
lib/mathematical/validator.rb,
lib/mathematical/corrections.rb,
ext/mathematical/mathematical.c
Defined Under Namespace
Modules: Corrections, Validator Classes: DocumentCreationError, DocumentReadError, MaxsizeError, ParseError, Process
Constant Summary collapse
- DEFAULT_OPTS =
{ :ppi => 72.0, :zoom => 1.0, :base64 => false, :maxsize => 0, :format => :svg, :delimiter => [:dollar, :double] }
- XML_HEADER =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
- VERSION =
'1.4.0'
Constants included from Validator
Validator::FORMAT_TYPES, Validator::RENDER_TYPES
Instance Method Summary collapse
- #filter(maths) ⇒ Object
-
#initialize(options = {}) ⇒ Mathematical
constructor
A new instance of Mathematical.
- #parse(maths) ⇒ Object (also: #render)
- #result(result_data) ⇒ Object
- #strict_filter(maths) ⇒ Object
- #text_filter(maths) ⇒ Object
Methods included from Validator
#validate_config, #validate_content, #validate_string
Methods included from Corrections
#adjust_lt_gt, #apply_corrections
Constructor Details
#initialize(options = {}) ⇒ Mathematical
Returns a new instance of Mathematical.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/mathematical.rb', line 25 def initialize( = {}) @config = DEFAULT_OPTS.merge() validate_config(@config) @config[:formatInt] = FORMAT_TYPES.index(@config[:format]) if @config[:delimiter].is_a?(Symbol) @config[:delimiter] = Configuration::Delimiters.to_h[@config[:delimiter]] else @config[:delimiter] = @config[:delimiter].map do |delim| Configuration::Delimiters.to_h[delim] end.inject(0, :|) end @processer = Mathematical::Process.new(@config) end |
Instance Method Details
#filter(maths) ⇒ Object
51 52 53 54 55 |
# File 'lib/mathematical.rb', line 51 def filter(maths) maths = validate_content(maths) result_data = @processer.process(maths, RENDER_TYPES.find_index(:filter)) result(result_data) end |
#parse(maths) ⇒ Object Also known as: render
43 44 45 46 47 |
# File 'lib/mathematical.rb', line 43 def parse(maths) maths = validate_content(maths) result_data = @processer.process(maths, RENDER_TYPES.find_index(:parse)) result(result_data) end |
#result(result_data) ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'lib/mathematical.rb', line 69 def result(result_data) fail RuntimeError if !result_data.is_a?(Hash) && !result_data.is_a?(Array) if result_data.is_a? Array result_data.map { |d| format_data(d) } else format_data(result_data) end end |
#strict_filter(maths) ⇒ Object
63 64 65 66 67 |
# File 'lib/mathematical.rb', line 63 def strict_filter(maths) maths = validate_content(maths) result_data = @processer.process(maths, RENDER_TYPES.find_index(:strict_filter)) result(result_data) end |
#text_filter(maths) ⇒ Object
57 58 59 60 61 |
# File 'lib/mathematical.rb', line 57 def text_filter(maths) maths = validate_content(maths) result_data = @processer.process(maths, RENDER_TYPES.find_index(:text_filter)) result(result_data) end |