Class: Ucode::Glyphs::LastResort::Contents

Inherits:
Object
  • Object
show all
Defined in:
lib/ucode/glyphs/last_resort/contents.rb

Overview

Parses the UFO ‘contents.plist` once into a `=> glif_basename` lookup.

The plist is the standard UFO v3 format:

<dict>
  <key>lastresortlatin</key>
  <string>lastresortlatin.glif</string>
  ...
</dict>

380 entries (one per placeholder glyph). Tiny file, but parsing it once per Writer avoids 380 redundant Nokogiri passes across the per-codepoint loop.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Contents

Returns a new instance of Contents.

Parameters:

  • path (String, Pathname, #to_path)

    contents.plist path



38
39
40
# File 'lib/ucode/glyphs/last_resort/contents.rb', line 38

def initialize(path)
  @path = Pathname.new(path)
end

Class Method Details

.parse(path) ⇒ Hash{String=>String}

Parse the plist file at ‘path` and return a frozen Hash.

Parameters:

  • path (String, Pathname, #to_path)

    contents.plist path

Returns:

  • (Hash{String=>String})

    glyph name → glif basename



33
34
35
# File 'lib/ucode/glyphs/last_resort/contents.rb', line 33

def self.parse(path)
  new(path).to_h
end

Instance Method Details

#[](glyph_name) ⇒ String?

Returns glif basename (e.g. “lastresortlatin.glif”).

Parameters:

  • glyph_name (String)

Returns:

  • (String, nil)

    glif basename (e.g. “lastresortlatin.glif”)



49
50
51
# File 'lib/ucode/glyphs/last_resort/contents.rb', line 49

def [](glyph_name)
  to_h[glyph_name]
end

#key?(glyph_name) ⇒ Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/ucode/glyphs/last_resort/contents.rb', line 54

def key?(glyph_name)
  to_h.key?(glyph_name)
end

#to_hHash{String=>String}

Returns frozen glyph name → glif basename.

Returns:

  • (Hash{String=>String})

    frozen glyph name → glif basename



43
44
45
# File 'lib/ucode/glyphs/last_resort/contents.rb', line 43

def to_h
  @to_h ||= build_index.freeze
end