Class: Fontist::Macos::Catalog::BaseParser
- Inherits:
-
Object
- Object
- Fontist::Macos::Catalog::BaseParser
- Defined in:
- lib/fontist/macos/catalog/base_parser.rb
Overview
Base parser for macOS Font catalogs Handles common parsing logic for Font7, Font8, etc.
Direct Known Subclasses
Font3Parser, Font4Parser, Font5Parser, Font6Parser, Font7Parser, Font8Parser
Instance Attribute Summary collapse
-
#xml_path ⇒ Object
readonly
Returns the value of attribute xml_path.
Instance Method Summary collapse
- #assets ⇒ Object
- #catalog_version ⇒ Object
- #framework_version ⇒ Object
-
#initialize(xml_path) ⇒ BaseParser
constructor
A new instance of BaseParser.
- #posted_date ⇒ Object
Constructor Details
#initialize(xml_path) ⇒ BaseParser
Returns a new instance of BaseParser.
11 12 13 14 |
# File 'lib/fontist/macos/catalog/base_parser.rb', line 11 def initialize(xml_path) @xml_path = xml_path @data = nil end |
Instance Attribute Details
#xml_path ⇒ Object (readonly)
Returns the value of attribute xml_path.
9 10 11 |
# File 'lib/fontist/macos/catalog/base_parser.rb', line 9 def xml_path @xml_path end |
Instance Method Details
#assets ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/fontist/macos/catalog/base_parser.rb', line 16 def assets posted_date_str = posted_date framework_ver = framework_version parse_assets.map do |asset_data| Asset.new(asset_data, posted_date: posted_date_str, framework_version: framework_ver) end end |
#catalog_version ⇒ Object
42 43 44 45 |
# File 'lib/fontist/macos/catalog/base_parser.rb', line 42 def catalog_version # Extract from filename: com_apple_MobileAsset_Font7.xml -> 7 File.basename(@xml_path).match(/Font(\d+)/)[1].to_i end |
#framework_version ⇒ Object
47 48 49 50 |
# File 'lib/fontist/macos/catalog/base_parser.rb', line 47 def framework_version # Extract from filename: com_apple_MobileAsset_Font7.xml -> 7 File.basename(@xml_path).match(/Font(\d+)/)[1].to_i end |
#posted_date ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/fontist/macos/catalog/base_parser.rb', line 25 def posted_date date_obj = data["postedDate"] return nil unless date_obj # Plist parser may return DateTime object directly if date_obj.is_a?(String) Time.parse(date_obj).utc.iso8601 elsif date_obj.respond_to?(:to_time) date_obj.to_time.utc.iso8601 else date_obj.to_s end rescue StandardError => e Fontist.ui.error("Could not parse postedDate: #{e.}") nil end |