fontist 0.2.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/macosx.yml +1 -1
- data/.github/workflows/ubuntu.yml +1 -1
- data/.gitignore +4 -3
- data/README.md +91 -5
- data/fontist.gemspec +1 -0
- data/lib/fontist.rb +26 -8
- data/lib/fontist/errors.rb +3 -0
- data/lib/fontist/font.rb +78 -0
- data/lib/fontist/font_formula.rb +123 -0
- data/lib/fontist/formula.rb +90 -0
- data/lib/fontist/formulas.rb +15 -0
- data/lib/fontist/formulas/andale_font.rb +79 -0
- data/lib/fontist/formulas/arial_black_font.rb +78 -0
- data/lib/fontist/formulas/cleartype_fonts.rb +226 -0
- data/lib/fontist/formulas/comic_font.rb +77 -0
- data/lib/fontist/formulas/courier_font.rb +80 -0
- data/lib/fontist/formulas/euphemia_font.rb +85 -0
- data/lib/fontist/formulas/georgia_font.rb +79 -0
- data/lib/fontist/formulas/impact_font.rb +77 -0
- data/lib/fontist/formulas/montserrat_font.rb +132 -0
- data/lib/fontist/formulas/ms_truetype_fonts.rb +124 -0
- data/lib/fontist/formulas/open_sans_fonts.rb +263 -0
- data/lib/fontist/formulas/overpass_font.rb +73 -0
- data/lib/fontist/formulas/source_fonts.rb +109 -0
- data/lib/fontist/formulas/stix_fonts.rb +108 -0
- data/lib/fontist/formulas/tahoma_font.rb +146 -0
- data/lib/fontist/formulas/webding_font.rb +77 -0
- data/lib/fontist/registry.rb +42 -0
- data/lib/fontist/system.yml +17 -0
- data/lib/fontist/system_font.rb +19 -12
- data/lib/fontist/utils.rb +9 -0
- data/lib/fontist/utils/downloader.rb +74 -0
- data/lib/fontist/utils/dsl.rb +77 -0
- data/lib/fontist/utils/exe_extractor.rb +72 -0
- data/lib/fontist/utils/zip_extractor.rb +38 -0
- data/lib/fontist/version.rb +1 -1
- data/spec/fontist/font_formula_spec.rb +67 -0
- data/spec/fontist/font_spec.rb +87 -0
- data/spec/fontist/formula_spec.rb +67 -0
- data/spec/fontist/formulas/andale_font_spec.rb +29 -0
- data/spec/fontist/formulas/arial_black_font_spec.rb +29 -0
- data/spec/fontist/formulas/cleartype_fonts_spec.rb +38 -0
- data/spec/fontist/formulas/comic_font_spec.rb +29 -0
- data/spec/fontist/formulas/courier_font_spec.rb +29 -0
- data/spec/fontist/formulas/euphemia_font_spec.rb +29 -0
- data/spec/fontist/formulas/georgia_font_spec.rb +29 -0
- data/spec/fontist/formulas/impact_font_spec.rb +29 -0
- data/spec/fontist/formulas/montserrat_font_spec.rb +29 -0
- data/spec/fontist/formulas/ms_truetype_fonts_spec.rb +29 -0
- data/spec/fontist/formulas/open_sans_fonts_spec.rb +29 -0
- data/spec/fontist/formulas/overpass_font_spec.rb +29 -0
- data/spec/fontist/formulas/source_fonts_spec.rb +31 -0
- data/spec/fontist/formulas/stix_fonts_spec.rb +29 -0
- data/spec/fontist/formulas/tahoma_font_spec.rb +29 -0
- data/spec/fontist/formulas/webding_font_spec.rb +29 -0
- data/spec/fontist/registry_spec.rb +47 -0
- data/spec/fontist/system_font_spec.rb +16 -0
- data/spec/fontist/{downloader_spec.rb → utils/downloader_spec.rb} +8 -8
- data/spec/spec_helper.rb +7 -2
- data/spec/support/fontist_helper.rb +10 -0
- metadata +65 -14
- data/assets/source.yml +0 -54
- data/lib/fontist/downloader.rb +0 -69
- data/lib/fontist/finder.rb +0 -47
- data/lib/fontist/installer.rb +0 -44
- data/lib/fontist/ms_vista_font.rb +0 -83
- data/lib/fontist/source.rb +0 -31
- data/spec/fontist/finder_spec.rb +0 -41
- data/spec/fontist/installer_spec.rb +0 -48
- data/spec/fontist/ms_vista_font_spec.rb +0 -27
- data/spec/fontist/source_spec.rb +0 -13
@@ -0,0 +1,29 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe Fontist::Formulas::StixFont do
|
4
|
+
describe "initializing" do
|
5
|
+
it "builds the data dictionary" do
|
6
|
+
formula = Fontist::Formulas::StixFont.instance
|
7
|
+
|
8
|
+
expect(formula.fonts.count).to eq(2)
|
9
|
+
expect(formula.fonts.first[:name]).to eq("STIX Two Math")
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "installation" do
|
14
|
+
context "with valid licence agreement" do
|
15
|
+
it "installs the valid fonts" do
|
16
|
+
name = "STIX Two Math"
|
17
|
+
confirmation = "yes"
|
18
|
+
|
19
|
+
stub_fontist_path_to_temp_path
|
20
|
+
paths = Fontist::Formulas::StixFont.fetch_font(
|
21
|
+
name, confirmation: confirmation
|
22
|
+
)
|
23
|
+
|
24
|
+
expect(Fontist::Font.find(name)).not_to be_empty
|
25
|
+
expect(paths.first).to include("fonts/STIX2Math.otf")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe Fontist::Formulas::TahomaFont do
|
4
|
+
describe "initializing" do
|
5
|
+
it "builds the data dictionary" do
|
6
|
+
formula = Fontist::Formulas::TahomaFont.instance
|
7
|
+
|
8
|
+
expect(formula.fonts.count).to eq(1)
|
9
|
+
expect(formula.fonts.first[:name]).to eq("Tahoma")
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "installation" do
|
14
|
+
context "with valid licence agreement", slow: true do
|
15
|
+
it "installs the valid fonts", skip_in_windows: true do
|
16
|
+
name = "Tahoma"
|
17
|
+
confirmation = "yes"
|
18
|
+
|
19
|
+
stub_fontist_path_to_temp_path
|
20
|
+
paths = Fontist::Formulas::TahomaFont.fetch_font(
|
21
|
+
name, confirmation: confirmation
|
22
|
+
)
|
23
|
+
|
24
|
+
expect(Fontist::Font.find(name)).not_to be_empty
|
25
|
+
expect(paths.first).to include("fonts/#{name.downcase}.ttf")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe Fontist::Formulas::WebdingFont do
|
4
|
+
describe "initializing" do
|
5
|
+
it "builds the data dictionary" do
|
6
|
+
formula = Fontist::Formulas::WebdingFont.instance
|
7
|
+
|
8
|
+
expect(formula.fonts.count).to eq(1)
|
9
|
+
expect(formula.fonts.first[:name]).to eq("Webdings")
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "installation" do
|
14
|
+
context "with valid licence agreement", slow: true do
|
15
|
+
it "installs the valid fonts", skip_in_windows: true do
|
16
|
+
name = "Webdings"
|
17
|
+
confirmation = "yes"
|
18
|
+
|
19
|
+
stub_fontist_path_to_temp_path
|
20
|
+
paths = Fontist::Formulas::WebdingFont.fetch_font(
|
21
|
+
name, confirmation: confirmation
|
22
|
+
)
|
23
|
+
|
24
|
+
expect(Fontist::Font.find(name)).not_to be_empty
|
25
|
+
expect(paths.first).to include("fonts/#{name}.TTF")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe Fontist::Registry do
|
4
|
+
describe ".register" do
|
5
|
+
context "with no key provided" do
|
6
|
+
it "registers a fontist formula with default key" do
|
7
|
+
Fontist::Registry.register(Fontist::Formulas::DemoFormula)
|
8
|
+
demo_formula = Fontist::Registry.formulas.demo_formula
|
9
|
+
|
10
|
+
expect(demo_formula.license).to eq("Vendor specific font licences")
|
11
|
+
expect(demo_formula.fonts.first.styles.first.type).to eq("Regular")
|
12
|
+
expect(demo_formula.installer).to eq("Fontist::Formulas::DemoFormula")
|
13
|
+
expect(demo_formula.homepage).to eq("https://github.com/fontist/fontist")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context "with custom key provided" do
|
18
|
+
it "registers the formula with this custom key" do
|
19
|
+
Fontist::Registry.register(Fontist::Formulas::DemoFormula, :custom_key)
|
20
|
+
|
21
|
+
expect(Fontist::Registry.formulas.custom_key).not_to be_nil
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
module Fontist
|
27
|
+
module Formulas
|
28
|
+
class DemoFormula < FontFormula
|
29
|
+
key :demo_formula
|
30
|
+
desc "Demo font formula"
|
31
|
+
homepage "https://github.com/fontist/fontist"
|
32
|
+
requires_license_agreement "Vendor specific font licences"
|
33
|
+
|
34
|
+
resource "demo-formula" do
|
35
|
+
urls [ "https://github.com/fontist/fontist" ]
|
36
|
+
sha256 "594e0f42e6581add4dead70c1dfb9"
|
37
|
+
file_size "1234567890"
|
38
|
+
end
|
39
|
+
|
40
|
+
provides_font "Demo font", match_styles_from_file: {
|
41
|
+
"Regular" => "demo-font.ttf",
|
42
|
+
"Italic" => "demo-fonti.ttf"
|
43
|
+
}
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -12,7 +12,23 @@ 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", slow: true do
|
17
|
+
name = "Calibri"
|
18
|
+
stub_fontist_path_to_temp_path
|
19
|
+
Fontist::Formulas::ClearTypeFonts.fetch_font(name, confirmation: "yes")
|
20
|
+
|
21
|
+
calbiri = Fontist::SystemFont.find(name, sources: [font_sources])
|
22
|
+
expect(calbiri.join("|").downcase).to include("#{name.downcase}.ttf")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
15
26
|
context "with invalid font" do
|
27
|
+
it "returns nil for partial-not match" do
|
28
|
+
name = "Deje"
|
29
|
+
expect(Fontist::SystemFont.find(name)).to be_nil
|
30
|
+
end
|
31
|
+
|
16
32
|
it "returns nill to the caller" do
|
17
33
|
name = "invalid-font.ttf"
|
18
34
|
invalid_font = Fontist::SystemFont.find(name, sources: [font_sources])
|
@@ -1,9 +1,9 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
RSpec.describe Fontist::Downloader do
|
4
|
-
describe ".download"
|
3
|
+
RSpec.describe Fontist::Utils::Downloader do
|
4
|
+
describe ".download" do
|
5
5
|
it "return the valid downloaded file" do
|
6
|
-
tempfile = Fontist::Downloader.download(
|
6
|
+
tempfile = Fontist::Utils::Downloader.download(
|
7
7
|
sample_file[:file],
|
8
8
|
sha: sample_file[:sha],
|
9
9
|
file_size: sample_file[:file_size],
|
@@ -15,20 +15,20 @@ RSpec.describe Fontist::Downloader do
|
|
15
15
|
|
16
16
|
it "raises an error for tempared file" do
|
17
17
|
expect{
|
18
|
-
Fontist::Downloader.download(
|
18
|
+
Fontist::Utils::Downloader.download(
|
19
19
|
sample_file[:file],
|
20
20
|
sha: sample_file[:sha] + "mm",
|
21
21
|
file_size: sample_file[:file_size]
|
22
22
|
)
|
23
|
-
}.to raise_error(Fontist::
|
23
|
+
}.to raise_error(Fontist::Errors::TemparedFileError)
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
27
|
def sample_file
|
28
28
|
@sample_file ||= {
|
29
|
-
file_size:
|
30
|
-
file: "https://
|
31
|
-
sha: "
|
29
|
+
file_size: 150899,
|
30
|
+
file: "https://drive.google.com/u/0/uc?id=1Kk-rpLyQk98ubgxhTRKD2ZkMoY9KqKXk&export=download",
|
31
|
+
sha: "5e513e4bfdada0ff10dd5b96414fcaeade84e235ce043865416ad7673cb6f3d8"
|
32
32
|
}
|
33
33
|
end
|
34
34
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,15 +1,20 @@
|
|
1
1
|
require "bundler/setup"
|
2
2
|
require "fontist"
|
3
3
|
|
4
|
+
Dir["./spec/support/**/*.rb"].sort.each { |file| require file }
|
5
|
+
|
4
6
|
RSpec.configure do |config|
|
5
7
|
# Enable flags like --only-failures and --next-failure
|
6
8
|
config.example_status_persistence_file_path = ".rspec_status"
|
9
|
+
config.include Fontist::Helper
|
7
10
|
|
8
11
|
# Disable RSpec exposing methods globally on `Module` and `main`
|
9
12
|
config.disable_monkey_patching!
|
10
13
|
|
11
|
-
# Skip the
|
12
|
-
|
14
|
+
# Skip the slow tests locally
|
15
|
+
unless ENV.fetch("TEST_ENV", "local").upcase === "CI"
|
16
|
+
config.filter_run_excluding slow: true
|
17
|
+
end
|
13
18
|
|
14
19
|
config.expect_with :rspec do |c|
|
15
20
|
c.syntax = :expect
|
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:
|
4
|
+
version: 1.2.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-
|
12
|
+
date: 2020-07-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: down
|
@@ -39,6 +39,20 @@ dependencies:
|
|
39
39
|
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: 0.1.0
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rubyzip
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 2.3.0
|
49
|
+
type: :runtime
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 2.3.0
|
42
56
|
- !ruby/object:Gem::Dependency
|
43
57
|
name: pry
|
44
58
|
requirement: !ruby/object:Gem::Requirement
|
@@ -112,30 +126,67 @@ files:
|
|
112
126
|
- LICENSE.txt
|
113
127
|
- README.md
|
114
128
|
- Rakefile
|
115
|
-
- assets/fonts/.keep
|
116
|
-
- assets/source.yml
|
117
129
|
- bin/console
|
118
130
|
- bin/rspec
|
119
131
|
- bin/setup
|
120
132
|
- fontist.gemspec
|
121
133
|
- lib/fontist.rb
|
122
|
-
- lib/fontist/downloader.rb
|
123
134
|
- lib/fontist/errors.rb
|
124
|
-
- lib/fontist/
|
125
|
-
- lib/fontist/
|
126
|
-
- lib/fontist/
|
127
|
-
- lib/fontist/
|
135
|
+
- lib/fontist/font.rb
|
136
|
+
- lib/fontist/font_formula.rb
|
137
|
+
- lib/fontist/formula.rb
|
138
|
+
- lib/fontist/formulas.rb
|
139
|
+
- lib/fontist/formulas/andale_font.rb
|
140
|
+
- lib/fontist/formulas/arial_black_font.rb
|
141
|
+
- lib/fontist/formulas/cleartype_fonts.rb
|
142
|
+
- lib/fontist/formulas/comic_font.rb
|
143
|
+
- lib/fontist/formulas/courier_font.rb
|
144
|
+
- lib/fontist/formulas/euphemia_font.rb
|
145
|
+
- lib/fontist/formulas/georgia_font.rb
|
146
|
+
- lib/fontist/formulas/impact_font.rb
|
147
|
+
- lib/fontist/formulas/montserrat_font.rb
|
148
|
+
- lib/fontist/formulas/ms_truetype_fonts.rb
|
149
|
+
- lib/fontist/formulas/open_sans_fonts.rb
|
150
|
+
- lib/fontist/formulas/overpass_font.rb
|
151
|
+
- lib/fontist/formulas/source_fonts.rb
|
152
|
+
- lib/fontist/formulas/stix_fonts.rb
|
153
|
+
- lib/fontist/formulas/tahoma_font.rb
|
154
|
+
- lib/fontist/formulas/webding_font.rb
|
155
|
+
- lib/fontist/registry.rb
|
156
|
+
- lib/fontist/system.yml
|
128
157
|
- lib/fontist/system_font.rb
|
158
|
+
- lib/fontist/utils.rb
|
159
|
+
- lib/fontist/utils/downloader.rb
|
160
|
+
- lib/fontist/utils/dsl.rb
|
161
|
+
- lib/fontist/utils/exe_extractor.rb
|
162
|
+
- lib/fontist/utils/zip_extractor.rb
|
129
163
|
- lib/fontist/version.rb
|
130
164
|
- spec/fixtures/fonts/DejaVuSerif.ttf
|
131
|
-
- spec/fontist/
|
132
|
-
- spec/fontist/
|
133
|
-
- spec/fontist/
|
134
|
-
- spec/fontist/
|
135
|
-
- spec/fontist/
|
165
|
+
- spec/fontist/font_formula_spec.rb
|
166
|
+
- spec/fontist/font_spec.rb
|
167
|
+
- spec/fontist/formula_spec.rb
|
168
|
+
- spec/fontist/formulas/andale_font_spec.rb
|
169
|
+
- spec/fontist/formulas/arial_black_font_spec.rb
|
170
|
+
- spec/fontist/formulas/cleartype_fonts_spec.rb
|
171
|
+
- spec/fontist/formulas/comic_font_spec.rb
|
172
|
+
- spec/fontist/formulas/courier_font_spec.rb
|
173
|
+
- spec/fontist/formulas/euphemia_font_spec.rb
|
174
|
+
- spec/fontist/formulas/georgia_font_spec.rb
|
175
|
+
- spec/fontist/formulas/impact_font_spec.rb
|
176
|
+
- spec/fontist/formulas/montserrat_font_spec.rb
|
177
|
+
- spec/fontist/formulas/ms_truetype_fonts_spec.rb
|
178
|
+
- spec/fontist/formulas/open_sans_fonts_spec.rb
|
179
|
+
- spec/fontist/formulas/overpass_font_spec.rb
|
180
|
+
- spec/fontist/formulas/source_fonts_spec.rb
|
181
|
+
- spec/fontist/formulas/stix_fonts_spec.rb
|
182
|
+
- spec/fontist/formulas/tahoma_font_spec.rb
|
183
|
+
- spec/fontist/formulas/webding_font_spec.rb
|
184
|
+
- spec/fontist/registry_spec.rb
|
136
185
|
- spec/fontist/system_font_spec.rb
|
186
|
+
- spec/fontist/utils/downloader_spec.rb
|
137
187
|
- spec/fontist_spec.rb
|
138
188
|
- spec/spec_helper.rb
|
189
|
+
- spec/support/fontist_helper.rb
|
139
190
|
homepage: https://github.com/fontist/fontist
|
140
191
|
licenses:
|
141
192
|
- BSD-2-Clause
|
data/assets/source.yml
DELETED
@@ -1,54 +0,0 @@
|
|
1
|
-
system:
|
2
|
-
linux:
|
3
|
-
paths:
|
4
|
-
- /usr/share/fonts/**/**.{ttf,ttc}
|
5
|
-
|
6
|
-
windows:
|
7
|
-
paths:
|
8
|
-
- C:/Windows/Fonts/**/**.{ttc,ttf}
|
9
|
-
|
10
|
-
macosx:
|
11
|
-
paths:
|
12
|
-
- /System/Library/Fonts/**/**.{ttf,ttc}
|
13
|
-
|
14
|
-
unix:
|
15
|
-
paths:
|
16
|
-
- /usr/share/fonts/**/**.{ttf,ttc}
|
17
|
-
|
18
|
-
remote:
|
19
|
-
msvista:
|
20
|
-
agreement: "yes"
|
21
|
-
|
22
|
-
fonts:
|
23
|
-
- CALIBRI.TTF
|
24
|
-
- CALIBRII.TTF
|
25
|
-
- CAMBRIA.TTC
|
26
|
-
- CAMBRIAI.TTF
|
27
|
-
- CANDARA.TTF
|
28
|
-
- CANDARAI.TTF
|
29
|
-
- CONSOLA.TTF
|
30
|
-
- CONSOLAI.TTF
|
31
|
-
- CONSTAN.TTF
|
32
|
-
- CONSTANI.TTF
|
33
|
-
- CORBEL.TTF
|
34
|
-
- CORBELI.TTF
|
35
|
-
- MEIRYO.TTC
|
36
|
-
- CALIBRIB.TTF
|
37
|
-
- CALIBRIZ.TTF
|
38
|
-
- CAMBRIAB.TTF
|
39
|
-
- CAMBRIAZ.TTF
|
40
|
-
- CANDARAB.TTF
|
41
|
-
- CANDARAZ.TTF
|
42
|
-
- CONSOLAB.TTF
|
43
|
-
- CONSOLAZ.TTF
|
44
|
-
- CONSTANB.TTF
|
45
|
-
- CONSTANZ.TTF
|
46
|
-
- CORBELB.TTF
|
47
|
-
- CORBELZ.TTF
|
48
|
-
- MEIRYOB.TTC
|
49
|
-
|
50
|
-
file_size: "62914560"
|
51
|
-
sha: "249473568eba7a1e4f95498acba594e0f42e6581add4dead70c1dfb908a09423"
|
52
|
-
urls:
|
53
|
-
- "https://www.dropbox.com/s/dl/6lclhxpydwgkjzh/PowerPointViewer.exe?dl=1"
|
54
|
-
- "https://web.archive.org/web/20171225132744/http://download.microsoft.com/download/E/6/7/E675FFFC-2A6D-4AB0-B3EB-27C9F8C8F696/PowerPointViewer.exe"
|
data/lib/fontist/downloader.rb
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
require "down"
|
2
|
-
require "digest"
|
3
|
-
|
4
|
-
module Fontist
|
5
|
-
class Downloader
|
6
|
-
def initialize(file, file_size: nil, sha: nil)
|
7
|
-
@sha = sha
|
8
|
-
@file = file
|
9
|
-
@file_size = file_size || default_file_size
|
10
|
-
end
|
11
|
-
|
12
|
-
def download
|
13
|
-
file = download_file
|
14
|
-
verify_file_checksum(file) || raise_invalid_file
|
15
|
-
end
|
16
|
-
|
17
|
-
def verify_file_checksum(file)
|
18
|
-
file if Digest::SHA256.file(file) === sha
|
19
|
-
end
|
20
|
-
|
21
|
-
def raise_invalid_file
|
22
|
-
raise(Fontist::Error, "Invalid / Tempared file")
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.download(file, options = {})
|
26
|
-
new(file, options).download
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
attr_reader :file, :sha, :file_size
|
32
|
-
|
33
|
-
def default_file_size
|
34
|
-
5 * byte_to_megabyte
|
35
|
-
end
|
36
|
-
|
37
|
-
def byte_to_megabyte
|
38
|
-
@byte_to_megabyte ||= 1024 * 1024
|
39
|
-
end
|
40
|
-
|
41
|
-
def download_path
|
42
|
-
options[:download_path] || Fontist.root_path.join("tmp")
|
43
|
-
end
|
44
|
-
|
45
|
-
def download_file
|
46
|
-
bar = ProgressBar.new(file_size / byte_to_megabyte)
|
47
|
-
|
48
|
-
Down.download(
|
49
|
-
@file,
|
50
|
-
progress_proc: -> (progress) {
|
51
|
-
bar.increment(progress / byte_to_megabyte)
|
52
|
-
}
|
53
|
-
)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
class ProgressBar
|
58
|
-
def initialize(total)
|
59
|
-
@counter = 1
|
60
|
-
@total = total
|
61
|
-
end
|
62
|
-
|
63
|
-
def increment(progress)
|
64
|
-
complete = sprintf("%#.2f%%", ((@counter.to_f / @total.to_f) * 100))
|
65
|
-
print "\r\e[0KDownloads: #{@counter}MB/#{@total}MB (#{complete})"
|
66
|
-
@counter = progress
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|