| Total Complexity | 9 |
| Total Lines | 48 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | 1 | require "tmpdir" |
|
| 11 | 1 | class FontDownloader |
|
| 12 | 1 | extend Forwardable |
|
| 13 | |||
| 14 | 1 | attr_reader :fonts |
|
| 15 | |||
| 16 | 1 | def self.local_files_present?(files) |
|
| 17 | 6 | files.all? { |file| File.file?(FileSystem.tmpfile_path(file)) } |
|
| 18 | end |
||
| 19 | 1 | private_class_method :local_files_present? |
|
| 20 | |||
| 21 | 1 | def initialize(fonts) |
|
| 22 | 8 | @fonts = fonts |
|
| 23 | end |
||
| 24 | |||
| 25 | 1 | def audit_font_dependencies |
|
| 26 | 3 | fonts.each do |font| |
|
| 27 | 2 | if self.class.__send__(:local_files_present?, font[:files].values) |
|
| 28 | 1 | fonts.delete(font) |
|
| 29 | end |
||
| 30 | end |
||
| 31 | end |
||
| 32 | |||
| 33 | 1 | def output_font_dependencies |
|
| 34 | 2 | return if fonts.none? |
|
| 35 | 1 | Output.warning(:custom_fonts) |
|
| 36 | end |
||
| 37 | |||
| 38 | 1 | def fonts_successfully_downloaded? |
|
| 39 | 3 | return true if fonts.none? |
|
| 40 | 2 | fonts.all? do |font| |
|
| 41 | 2 | download_and_extract_font(font) |
|
| 42 | 1 | true |
|
| 43 | end |
||
| 44 | rescue NetworkConnectionError |
||
| 45 | 1 | false |
|
| 46 | end |
||
| 47 | |||
| 48 | 1 | private |
|
| 49 | |||
| 50 | 1 | def download_and_extract_font(font) |
|
| 51 | 2 | Output.plain(:downloading_font) |
|
| 52 | 2 | FileFetcher.fetch( |
|
| 53 | ContentParser.decode_content(font[:location]) |
||
| 54 | ) |
||
| 55 | 1 | require "zip" |
|
| 56 | 1 | FontExtractor.extract(font) |
|
| 57 | end |
||
| 58 | end |
||
| 59 | end |
||
| 61 |