Class: Fontist::Font

Inherits:
Object
  • Object
show all
Defined in:
lib/fontist/font.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Font

Returns a new instance of Font.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/fontist/font.rb', line 5

def initialize(options = {})
  @name = options[:name]
  @confirmation = options[:confirmation] || "no"
  @hide_licenses = options[:hide_licenses]
  @no_progress = options[:no_progress] || false
  @force = options[:force] || false
  @version = options[:version]
  @smallest = options[:smallest]
  @newest = options[:newest]
  @size_limit = options[:size_limit]
  @by_formula = options[:formula]
  @update_fontconfig = options[:update_fontconfig]
  @install_location = options[:location] || options[:install_location]

  # Accept FormatSpec or create from options
  @format_spec = options[:format_spec] || FormatSpec.from_options(options)

  validate_location_parameter!
  check_or_create_fontist_path!
end

Class Method Details

.allObject



26
27
28
# File 'lib/fontist/font.rb', line 26

def self.all
  new.all
end

.find(name) ⇒ Object



30
31
32
# File 'lib/fontist/font.rb', line 30

def self.find(name)
  new(name: name).find
end

.install(name, options = {}) ⇒ Object



34
35
36
# File 'lib/fontist/font.rb', line 34

def self.install(name, options = {})
  new(options.merge(name: name)).install
end

.install_many(names, options = {}) ⇒ Object



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

def self.install_many(names, options = {})
  successes = []
  failures = []

  names.each do |name|
    install(name, options)
    successes << name
  rescue Fontist::Errors::GeneralError => e
    failures << { font: name, error: e }
  end

  { successes: successes, failures: failures }
end

.list(name) ⇒ Object



60
61
62
# File 'lib/fontist/font.rb', line 60

def self.list(name)
  new(name: name).list
end

.status(name) ⇒ Object



56
57
58
# File 'lib/fontist/font.rb', line 56

def self.status(name)
  new(name: name).status
end

.uninstall(name) ⇒ Object



52
53
54
# File 'lib/fontist/font.rb', line 52

def self.uninstall(name)
  new(name: name).uninstall
end

Instance Method Details

#allObject



94
95
96
# File 'lib/fontist/font.rb', line 94

def all
  all_formulas.map(&:fonts).flatten
end

#findObject



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

def find
  find_system_font || downloadable_font || manual_font ||
    raise_non_supported_font
end

#installObject



69
70
71
72
73
74
# File 'lib/fontist/font.rb', line 69

def install
  return install_formula if @by_formula

  (find_system_font unless @force) || download_font || manual_font ||
    raise_non_supported_font
end

#listObject



88
89
90
91
92
# File 'lib/fontist/font.rb', line 88

def list
  return all_list unless @name

  font_list || raise_non_supported_font
end

#statusObject



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

def status
  return installed_paths unless @name

  find_system_font || downloadable_font || manual_font ||
    raise_non_supported_font
end

#uninstallObject



76
77
78
79
# File 'lib/fontist/font.rb', line 76

def uninstall
  uninstall_font || downloadable_font || manual_font ||
    raise_non_supported_font
end