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) ⇒ 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) ⇒ TableAnalyzer
Initialize analyzer with fonts
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/fontisan/collection/table_analyzer.rb', line 27 def initialize(fonts) 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 @report = nil 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.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/fontisan/collection/table_analyzer.rb', line 51 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
76 77 78 79 |
# File 'lib/fontisan/collection/table_analyzer.rb', line 76 def shared_tables analyze unless @report @report[:shared_tables] end |
#sharing_percentage ⇒ Float
Get sharing percentage
92 93 94 95 |
# File 'lib/fontisan/collection/table_analyzer.rb', line 92 def sharing_percentage analyze unless @report @report[:sharing_percentage] end |
#space_savings ⇒ Integer
Get potential space savings in bytes
84 85 86 87 |
# File 'lib/fontisan/collection/table_analyzer.rb', line 84 def space_savings analyze unless @report @report[:space_savings] end |