Class: Mathtype::EpsFileParser
- Inherits:
-
FileParser
- Object
- FileParser
- Mathtype::EpsFileParser
- Defined in:
- lib/mathtype-0.0.7.5/lib/file_parser/eps.rb
Constant Summary
Constants inherited from FileParser
Instance Attribute Summary
Attributes inherited from FileParser
Instance Method Summary collapse
- #extract_mtef_from_epscomment(comment) ⇒ Object
-
#initialize(path) ⇒ EpsFileParser
constructor
A new instance of EpsFileParser.
Methods inherited from FileParser
#checksum, #decode, #encode, #read_from_file
Constructor Details
#initialize(path) ⇒ EpsFileParser
Returns a new instance of EpsFileParser.
3 4 5 6 |
# File 'lib/mathtype-0.0.7.5/lib/file_parser/eps.rb', line 3 def initialize(path) super(path) extract_mtef_from_epscomment(@raw) end |
Instance Method Details
#extract_mtef_from_epscomment(comment) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/mathtype-0.0.7.5/lib/file_parser/eps.rb', line 8 def extract_mtef_from_epscomment(comment) string64 = @raw.gsub /\r/, "" # d for delimiter d = string64[(/MathType(.)MTEF\1/ =~ string64) + 8] matches = string64.match /.*MathType#{d}MTEF#{d}(.)#{d}(.)#{d}(.)(.)(.*)#{d}([0-9A-F]{4})#{d}.*/m leading_chrs = matches[1].to_i trailing_chrs = matches[2].to_i - 1 a64_chr1 = matches[3] a64_chr2 = matches[4] A64[a64_chr1] = 62 A64[a64_chr2] = 63 A64[62] = a64_chr1 A64[63] = a64_chr2 string64 = matches[5] mtchecksum = matches[6] string64.gsub! /.{#{trailing_chrs}}(\n).{#{leading_chrs}}/m, "" @equation = decode string64 unless checksum == mtchecksum raise ArgumentError, "Checksums do not match, expected #{mtchecksum} but got #{checksum}" end end |