Class: Fontisan::Collection::TableAnalyzer
- Inherits:
-
Object
- Object
- Fontisan::Collection::TableAnalyzer
- Defined in:
- lib/fontisan/collection/table_analyzer.rb
Overview
TableAnalyzer analyzes tables across multiple fonts to identify sharing opportunities
Single responsibility: Analyze tables across fonts to identify identical tables that can be shared in a font collection. Uses SHA256 checksums for reliable content comparison.
Instance Attribute Summary collapse
-
#report ⇒ Hash
readonly
Analysis report structure.
Instance Method Summary collapse
-
#analyze ⇒ Hash
Analyze tables across all fonts.
-
#initialize(fonts, parallel: false, thread_count: 4) ⇒ TableAnalyzer
constructor
Initialize analyzer with fonts.
-
#shared_tables ⇒ Hash<String, Array<Integer>>
Get tables that can be shared.
-
#sharing_percentage ⇒ Float
Get sharing percentage.
-
#space_savings ⇒ Integer
Get potential space savings in bytes.
Constructor Details
#initialize(fonts, parallel: false, thread_count: 4) ⇒ TableAnalyzer
Initialize analyzer with fonts
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/fontisan/collection/table_analyzer.rb', line 29 def initialize(fonts, parallel: false, thread_count: 4) if fonts.nil? || fonts.empty? raise ArgumentError, "fonts cannot be nil or empty" end raise ArgumentError, "fonts must be an array" unless fonts.is_a?(Array) @fonts = fonts @parallel = parallel @thread_count = thread_count @report = nil @checksum_cache = {}.compare_by_identity end |
Instance Attribute Details
#report ⇒ Hash (readonly)
Analysis report structure
21 22 23 |
# File 'lib/fontisan/collection/table_analyzer.rb', line 21 def report @report end |
Instance Method Details
#analyze ⇒ Hash
Analyze tables across all fonts
Identifies tables that are identical across fonts based on content checksum. Returns a comprehensive analysis report with sharing opportunities and potential space savings.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/fontisan/collection/table_analyzer.rb', line 56 def analyze @report = { total_fonts: @fonts.size, table_checksums: {}, shared_tables: {}, unique_tables: {}, space_savings: 0, sharing_percentage: 0.0, } # Collect checksums for all tables across all fonts collect_table_checksums # Identify which tables are shared identify_shared_tables # Calculate space savings calculate_space_savings @report end |
#shared_tables ⇒ Hash<String, Array<Integer>>
Get tables that can be shared
81 82 83 84 |
# File 'lib/fontisan/collection/table_analyzer.rb', line 81 def shared_tables analyze unless @report @report[:shared_tables] end |
#sharing_percentage ⇒ Float
Get sharing percentage
97 98 99 100 |
# File 'lib/fontisan/collection/table_analyzer.rb', line 97 def sharing_percentage analyze unless @report @report[:sharing_percentage] end |
#space_savings ⇒ Integer
Get potential space savings in bytes
89 90 91 92 |
# File 'lib/fontisan/collection/table_analyzer.rb', line 89 def space_savings analyze unless @report @report[:space_savings] end |