Class: Fontist::SystemFont
- Inherits:
-
Object
- Object
- Fontist::SystemFont
- Defined in:
- lib/fontist/system_font.rb
Class Method Summary collapse
- .expand_paths(paths) ⇒ Object
- .find(font) ⇒ Object
- .find_styles(font, style) ⇒ Object
- .font_paths ⇒ Object
- .fontist_font_paths ⇒ Object
- .load_system_font_paths ⇒ Object
- .reset_system_font_paths_cache ⇒ Object
- .system_config ⇒ Object
- .system_font_paths ⇒ Object
Instance Method Summary collapse
- #find ⇒ Object
- #find_styles ⇒ Object
-
#initialize(font:, style: nil) ⇒ SystemFont
constructor
A new instance of SystemFont.
Constructor Details
#initialize(font:, style: nil) ⇒ SystemFont
Returns a new instance of SystemFont.
5 6 7 8 |
# File 'lib/fontist/system_font.rb', line 5 def initialize(font:, style: nil) @font = font @style = style end |
Class Method Details
.expand_paths(paths) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/fontist/system_font.rb', line 36 def self.(paths) paths.map do |path| require "etc" passwd = Etc.getpwuid username = passwd ? passwd.name : Etc.getlogin username ? path.gsub("{username}", username) : path end end |
.find(font) ⇒ Object
50 51 52 |
# File 'lib/fontist/system_font.rb', line 50 def self.find(font) new(font: font).find end |
.find_styles(font, style) ⇒ Object
54 55 56 |
# File 'lib/fontist/system_font.rb', line 54 def self.find_styles(font, style) new(font: font, style: style).find_styles end |
.font_paths ⇒ Object
10 11 12 |
# File 'lib/fontist/system_font.rb', line 10 def self.font_paths system_font_paths + fontist_font_paths end |
.fontist_font_paths ⇒ Object
46 47 48 |
# File 'lib/fontist/system_font.rb', line 46 def self.fontist_font_paths Dir.glob(Fontist.fonts_path.join("**")) end |
.load_system_font_paths ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/fontist/system_font.rb', line 18 def self.load_system_font_paths os = Fontist::Utils::System.user_os.to_s templates = system_config["system"][os]["paths"] patterns = (templates) Dir.glob(patterns) # File::FNM_CASEFOLD is officially ignored -- see https://ruby-doc.org/core-3.1.1/Dir.html#method-c-glob # "Case sensitivity depends on your system" end |
.reset_system_font_paths_cache ⇒ Object
32 33 34 |
# File 'lib/fontist/system_font.rb', line 32 def self.reset_system_font_paths_cache @system_font_paths = nil end |
.system_config ⇒ Object
28 29 30 |
# File 'lib/fontist/system_font.rb', line 28 def self.system_config YAML.load_file(Fontist.system_file_path) end |
.system_font_paths ⇒ Object
14 15 16 |
# File 'lib/fontist/system_font.rb', line 14 def self.system_font_paths @system_font_paths ||= load_system_font_paths end |
Instance Method Details
#find ⇒ Object
58 59 60 61 62 63 |
# File 'lib/fontist/system_font.rb', line 58 def find styles = find_styles return unless styles styles.map { |x| x[:path] } end |
#find_styles ⇒ Object
65 66 67 |
# File 'lib/fontist/system_font.rb', line 65 def find_styles find_by_index end |