Class: Fontist::SystemIndex

Inherits:
Object
  • Object
show all
Includes:
Utils::Locking
Defined in:
lib/fontist/system_index.rb

Defined Under Namespace

Classes: DefaultFamily, PreferredFamily

Constant Summary collapse

ALLOWED_KEYS =
%i[path full_name family_name type].freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utils::Locking

#lock

Constructor Details

#initialize(index_path, font_paths_fetcher, family) ⇒ SystemIndex

Returns a new instance of SystemIndex.



73
74
75
76
77
# File 'lib/fontist/system_index.rb', line 73

def initialize(index_path, font_paths_fetcher, family)
  @index_path = index_path
  @font_paths_fetcher = font_paths_fetcher
  @family = family
end

Class Method Details

.familyObject



65
66
67
# File 'lib/fontist/system_index.rb', line 65

def self.family
  Fontist.preferred_family? ? PreferredFamily.new : DefaultFamily.new
end

.fontist_indexObject



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/fontist/system_index.rb', line 52

def self.fontist_index
  path = if Fontist.preferred_family?
           Fontist.fontist_preferred_family_index_path
         else
           Fontist.fontist_index_path
         end

  @fontist_index ||= {}
  @fontist_index[Fontist.preferred_family?] ||= {}
  @fontist_index[Fontist.preferred_family?][path] ||=
    new(path, -> { SystemFont.fontist_font_paths }, family)
end

.system_indexObject



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/fontist/system_index.rb', line 39

def self.system_index
  path = if Fontist.preferred_family?
           Fontist.system_preferred_family_index_path
         else
           Fontist.system_index_path
         end

  @system_index ||= {}
  @system_index[Fontist.preferred_family?] ||= {}
  @system_index[Fontist.preferred_family?][path] ||=
    new(path, -> { SystemFont.font_paths }, family)
end

Instance Method Details

#excluded_fontsObject



69
70
71
# File 'lib/fontist/system_index.rb', line 69

def excluded_fonts
  @excluded_fonts ||= YAML.load_file(Fontist.excluded_fonts_path)
end

#find(font, style) ⇒ Object



79
80
81
82
83
84
85
86
# File 'lib/fontist/system_index.rb', line 79

def find(font, style)
  fonts = index.select do |file|
    file[:family_name].casecmp?(font) &&
      (style.nil? || file[:type].casecmp?(style))
  end

  fonts.empty? ? nil : fonts
end

#rebuildObject



88
89
90
# File 'lib/fontist/system_index.rb', line 88

def rebuild
  build_index
end