Guest User

Untitled

a guest
May 25th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. class TTFunk
  2. class File
  3. def initialize(file)
  4. ::File.open(file,"rb") do |fh|
  5. @directory = Table::Directory.new(fh)
  6. end
  7. end
  8.  
  9. attr_reader :directory
  10. end
  11.  
  12. class Table
  13.  
  14. class Directory < Table
  15. def initialize(fh)
  16. @scaler_type, @table_count, @search_rage,
  17. @entry_selector, @range_shift = fh.read(12).unpack("Nnnnn")
  18. parse_table_list(fh)
  19. end
  20.  
  21. def parse_table_list(fh)
  22. first_table = parse_table(fh)
  23. @tables = first_table
  24. offset = first_table[first_table.keys.first][:offset]
  25.  
  26. @tables.update(parse_table(fh)) while fh.pos < offset
  27. end
  28.  
  29. def parse_table(fh)
  30. tag, checksum, offset, length = fh.read(16).unpack("a4NNN")
  31. { tag => {
  32. :checksum => checksum, :offset => offset, :length => length } }
  33. end
  34.  
  35. end
  36.  
  37. def method_missing(*args, &block)
  38. var = "@#{args.first}"
  39. instance_variables.include?(var) ? instance_variable_get(var) : super
  40. end
  41.  
  42. end
  43. end
Add Comment
Please, Sign In to add comment