fontist 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -20,28 +20,23 @@ module Fontist
20
20
 
21
21
  attr_reader :font_name, :confirmation, :options
22
22
 
23
- def downloaders
24
- {
25
- msvista: Fontist::Formulas::MsVista,
26
- source_front: Fontist::Formulas::SourceFont,
27
- }
28
- end
29
-
30
23
  def find_system_font
31
24
  Fontist::SystemFont.find(font_name)
32
25
  end
33
26
 
34
- def download_font
35
- if !font_sources.empty?
36
- downloader = downloaders[font_sources.first]
37
- downloader.fetch_font(font_name, confirmation: confirmation)
38
- end
27
+ def font_formulas
28
+ Fontist::FormulaFinder.find(font_name)
39
29
  end
40
30
 
41
- def font_sources
42
- @font_sources ||= Fontist::Source.formulas.to_h.select do |key, value|
43
- !value.fonts.grep(/#{font_name}/i).empty?
44
- end.keys
31
+ def download_font
32
+ if font_formulas
33
+ font_formulas.map do |formula|
34
+ formula[:installer].fetch_font(
35
+ font_name,
36
+ confirmation: confirmation,
37
+ )
38
+ end.flatten
39
+ end
45
40
  end
46
41
  end
47
42
  end
@@ -13,6 +13,8 @@ module Fontist
13
13
 
14
14
  def find
15
15
  paths = font_paths.grep(/#{font}/i)
16
+ paths = lookup_using_font_name || [] if paths.empty?
17
+
16
18
  paths.empty? ? nil : paths
17
19
  end
18
20
 
@@ -35,6 +37,11 @@ module Fontist
35
37
  ).flatten.uniq)
36
38
  end
37
39
 
40
+ def lookup_using_font_name
41
+ font_names = map_name_to_valid_font_names
42
+ font_paths.grep(/#{font_names.join("|")}/i) if font_names
43
+ end
44
+
38
45
  def fontist_fonts_path
39
46
  @fontist_fonts_path ||= Fontist.fonts_path
40
47
  end
@@ -61,5 +68,9 @@ module Fontist
61
68
  )
62
69
  end
63
70
 
71
+ def map_name_to_valid_font_names
72
+ fonts = FormulaFinder.find_fonts(font)
73
+ fonts.map { |font| font.styles.map(&:font) }.flatten if fonts
74
+ end
64
75
  end
65
76
  end
@@ -1,3 +1,3 @@
1
1
  module Fontist
2
- VERSION = "0.3.0".freeze
2
+ VERSION = "0.4.0".freeze
3
3
  end
@@ -14,7 +14,7 @@ RSpec.describe Fontist::Finder do
14
14
 
15
15
  context "with downloadable ms vista font" do
16
16
  it "returns missing font error" do
17
- name = "CALIBRI.TTF"
17
+ name = "Calibri"
18
18
  allow(Fontist::SystemFont).to receive(:find).and_return(nil)
19
19
 
20
20
  expect {
@@ -0,0 +1,54 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Fontist::FormulaFinder do
4
+ describe ".find" do
5
+ context "by font name" do
6
+ it "returns the font formulas" do
7
+ name = "Calibri"
8
+ formulas = Fontist::FormulaFinder.find(name)
9
+
10
+ expect(formulas.count).to eq(1)
11
+ expect(formulas.first[:key]).to eq("msvista")
12
+ expect(formulas.first[:installer]).to eq(Fontist::Formulas::MsVista)
13
+ end
14
+ end
15
+
16
+ context "by exact font" do
17
+ it "returns the font formulas" do
18
+ name = "CAMBRIAI.TTF"
19
+ formulas = Fontist::FormulaFinder.find(name)
20
+
21
+ expect(formulas.count).to eq(1)
22
+ expect(formulas.first[:key]).to eq("msvista")
23
+ expect(formulas.first[:installer]).to eq(Fontist::Formulas::MsVista)
24
+ end
25
+ end
26
+
27
+ context "for invalid font" do
28
+ it "returns nil to the caller" do
29
+ name = "Calibri Made Up Name"
30
+ formulas = Fontist::FormulaFinder.find(name)
31
+
32
+ expect(formulas).to be_nil
33
+ end
34
+ end
35
+ end
36
+
37
+ describe ".find_fonts" do
38
+ it "returns the exact font font names" do
39
+ name = "Calibri"
40
+ font = Fontist::FormulaFinder.find_fonts(name).first
41
+
42
+ expect(font.styles.map(&:font)).to include("CALIBRI.TTF")
43
+ expect(font.styles.map(&:font)).to include("CALIBRIB.TTF")
44
+ expect(font.styles.map(&:font)).to include("CALIBRII.TTF")
45
+ end
46
+
47
+ it "returns nil if invalid name provided" do
48
+ name = "Calibri Invlaid"
49
+ fonts = Fontist::FormulaFinder.find_fonts(name)
50
+
51
+ expect(fonts).to be_nil
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,30 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Fontist::Formulas::CourierFont do
4
+ describe ".fetch_font" do
5
+ context "with valid licence", skip_in_windows: true do
6
+ it "downloads and returns the fonts" do
7
+ name = "Courier"
8
+ stub_fontist_path_to_assets
9
+ fonts = Fontist::Formulas::CourierFont.fetch_font(
10
+ name, confirmation: "yes", force_download: true
11
+ )
12
+
13
+ expect(fonts.count).to eq(4)
14
+ expect(fonts.first).to include("fonts/cour.ttf")
15
+ expect(Fontist::Finder.find(name)).not_to be_empty
16
+ end
17
+ end
18
+
19
+ context "with invalid licence agreement" do
20
+ it "raise an licensing error" do
21
+ font_name = "cour"
22
+ stub_fontist_path_to_assets
23
+
24
+ expect {
25
+ Fontist::Formulas::CourierFont.fetch_font(font_name, confirmation: "no")
26
+ }.to raise_error(Fontist::Errors::LicensingError)
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,31 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Fontist::Formulas::MsSystem do
4
+ describe ".fetch_font" do
5
+ context "with valid licence", skip_in_windows: false do
6
+ it "downloads and returns font paths", file_download: true do
7
+ name = "Times"
8
+ stub_fontist_path_to_assets
9
+
10
+ fonts = Fontist::Formulas::MsSystem.fetch_font(
11
+ name, confirmation: "yes"
12
+ )
13
+
14
+ expect(fonts).not_to be_empty
15
+ expect(fonts.first).to include(name)
16
+ expect(Fontist::Finder.find(name)).not_to be_empty
17
+ end
18
+ end
19
+
20
+ context "with invalid licence agreement" do
21
+ it "raise an licensing error" do
22
+ font_name = "Times"
23
+ stub_fontist_path_to_assets
24
+
25
+ expect {
26
+ Fontist::Formulas::MsSystem.fetch_font(font_name, confirmation: "no")
27
+ }.to raise_error(Fontist::Errors::LicensingError)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -2,11 +2,11 @@ require "spec_helper"
2
2
 
3
3
  RSpec.describe Fontist::Formulas::MsVista do
4
4
  describe ".fetch_font" do
5
- context "with valid licence", file_download: true do
6
- it "downloads and returns font paths" do
5
+ context "with valid licence" do
6
+ it "downloads and returns font paths", file_download: true do
7
7
  name = "CANDARAI.TTF"
8
8
  fonts = Fontist::Formulas::MsVista.fetch_font(
9
- name, confirmation: "yes", force_download: true
9
+ name, confirmation: "yes"
10
10
  )
11
11
 
12
12
  expect(fonts.count).to eq(1)
@@ -3,8 +3,8 @@ require "spec_helper"
3
3
  RSpec.describe Fontist::Installer do
4
4
  describe ".download" do
5
5
  context "with already downloaded fonts", skip_in_windows: true do
6
- it "returns the font path" do
7
- name = "CALIBRI.TTF"
6
+ it "returns the font path", file_download: true do
7
+ name = "Arial"
8
8
  Fontist::Formulas::MsVista.fetch_font(name, confirmation: "yes")
9
9
 
10
10
  allow(Fontist::Formulas::MsVista).to receive(:fetch_font).and_return(nil)
@@ -16,7 +16,7 @@ RSpec.describe Fontist::Installer do
16
16
 
17
17
  context "with missing but downloadable fonts" do
18
18
  it "downloads and install the fonts", skip_in_windows: true do
19
- name = "CALIBRI.TTF"
19
+ name = "Arial"
20
20
  confirmation = "yes"
21
21
  allow(Fontist::SystemFont).to receive(:find).and_return(nil)
22
22
 
@@ -26,7 +26,7 @@ RSpec.describe Fontist::Installer do
26
26
  end
27
27
 
28
28
  it "do not download if user didn't agree" do
29
- name = "CALIBRI.TTF"
29
+ name = "Calibri"
30
30
  allow(Fontist::SystemFont).to receive(:find).and_return(nil)
31
31
 
32
32
  expect {
@@ -18,7 +18,7 @@ RSpec.describe Fontist::Source do
18
18
 
19
19
  expect(formulas.msvista.license).not_to be_nil
20
20
  expect(formulas.msvista.file_size).to eq("62914560")
21
- expect(formulas.msvista.fonts).to include("CALIBRI.TTF")
21
+ expect(formulas.msvista.fonts.map(&:name)).to include("Calibri")
22
22
  end
23
23
  end
24
24
  end
@@ -12,6 +12,17 @@ RSpec.describe Fontist::SystemFont do
12
12
  end
13
13
  end
14
14
 
15
+ context "with valid font name" do
16
+ it "returns the complete font path", file_download: true do
17
+ name = "Courier"
18
+ stub_fontist_path_to_assets
19
+ Fontist::Formulas::CourierFont.fetch_font(name, confirmation: "yes")
20
+
21
+ courier = Fontist::SystemFont.find(name, sources: [font_sources])
22
+ expect(courier.first).to include("cour.ttf")
23
+ end
24
+ end
25
+
15
26
  context "with invalid font" do
16
27
  it "returns nill to the caller" do
17
28
  name = "invalid-font.ttf"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fontist
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-05-08 00:00:00.000000000 Z
12
+ date: 2020-05-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: down
@@ -132,14 +132,21 @@ files:
132
132
  - bin/setup
133
133
  - fontist.gemspec
134
134
  - lib/fontist.rb
135
+ - lib/fontist/data/formulas/courier.yml
136
+ - lib/fontist/data/formulas/ms_system.yml
135
137
  - lib/fontist/data/formulas/ms_vista.yml
136
138
  - lib/fontist/data/formulas/source_font.yml
137
139
  - lib/fontist/data/source.yml
138
140
  - lib/fontist/downloader.rb
139
141
  - lib/fontist/errors.rb
140
142
  - lib/fontist/finder.rb
143
+ - lib/fontist/formula_finder.rb
141
144
  - lib/fontist/formulas.rb
142
145
  - lib/fontist/formulas/base.rb
146
+ - lib/fontist/formulas/courier_font.rb
147
+ - lib/fontist/formulas/helpers/exe_extractor.rb
148
+ - lib/fontist/formulas/helpers/zip_extractor.rb
149
+ - lib/fontist/formulas/ms_system.rb
143
150
  - lib/fontist/formulas/ms_vista.rb
144
151
  - lib/fontist/formulas/source_font.rb
145
152
  - lib/fontist/installer.rb
@@ -149,6 +156,9 @@ files:
149
156
  - spec/fixtures/fonts/DejaVuSerif.ttf
150
157
  - spec/fontist/downloader_spec.rb
151
158
  - spec/fontist/finder_spec.rb
159
+ - spec/fontist/formula_finder_spec.rb
160
+ - spec/fontist/formulas/courier_font_spec.rb
161
+ - spec/fontist/formulas/ms_system_spec.rb
152
162
  - spec/fontist/formulas/ms_vista_spec.rb
153
163
  - spec/fontist/formulas/source_font_spec.rb
154
164
  - spec/fontist/installer_spec.rb