Class: FluentIcons::Scanner
- Inherits:
-
Object
- Object
- FluentIcons::Scanner
- Defined in:
- lib/fluent-icons/scanner.rb
Instance Attribute Summary collapse
-
#files_scanned ⇒ Object
readonly
Returns the value of attribute files_scanned.
-
#icons_found ⇒ Object
readonly
Returns the value of attribute icons_found.
Instance Method Summary collapse
-
#compile(output_path:, source_data_path: nil) ⇒ Object
Generate compiled data.json with only used icons.
-
#initialize(paths: default_paths, verbose: false) ⇒ Scanner
constructor
A new instance of Scanner.
-
#report ⇒ Object
Generate report of icon usage.
-
#scan ⇒ Object
Scan all files and return found icons.
Constructor Details
#initialize(paths: default_paths, verbose: false) ⇒ Scanner
Returns a new instance of Scanner.
8 9 10 11 12 13 |
# File 'lib/fluent-icons/scanner.rb', line 8 def initialize(paths: default_paths, verbose: false) @paths = Array(paths) @icons_found = Set.new @files_scanned = 0 @verbose = verbose end |
Instance Attribute Details
#files_scanned ⇒ Object (readonly)
Returns the value of attribute files_scanned.
6 7 8 |
# File 'lib/fluent-icons/scanner.rb', line 6 def files_scanned @files_scanned end |
#icons_found ⇒ Object (readonly)
Returns the value of attribute icons_found.
6 7 8 |
# File 'lib/fluent-icons/scanner.rb', line 6 def icons_found @icons_found end |
Instance Method Details
#compile(output_path:, source_data_path: nil) ⇒ Object
Generate compiled data.json with only used icons
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/fluent-icons/scanner.rb', line 34 def compile(output_path:, source_data_path: nil) icons = scan if icons.empty? warn "[FluentIcons::Scanner] No icons found. Compiled file will be empty." else puts "[FluentIcons::Scanner] Found #{icons.count} unique icons in #{@files_scanned} files" end # Load full data.json source_data_path ||= File.join(File.dirname(__FILE__), '..', 'build', 'data.json') unless File.exist?(source_data_path) raise "[FluentIcons::Scanner] Source data file not found: #{source_data_path}" end full_data = JSON.parse(File.read(source_data_path)) # Filter to only used icons compiled_data = {} icons.each do |icon| if full_data[icon] compiled_data[icon] = full_data[icon] else warn "[FluentIcons::Scanner] Warning: Icon '#{icon}' not found in data.json" if @verbose end end # Write compiled data File.write(output_path, JSON.pretty_generate(compiled_data)) original_size = File.size(source_data_path) compiled_size = File.size(output_path) reduction_pct = ((1 - compiled_size.to_f / original_size) * 100).round(2) puts "[FluentIcons::Scanner] Compilation complete!" puts " Original size: #{human_size(original_size)}" puts " Compiled size: #{human_size(compiled_size)}" puts " Reduction: #{reduction_pct}%" puts " Output: #{output_path}" { icons_count: compiled_data.keys.count, original_size: original_size, compiled_size: compiled_size, reduction_percent: reduction_pct, output_path: output_path } end |
#report ⇒ Object
Generate report of icon usage
85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/fluent-icons/scanner.rb', line 85 def report icons = scan puts "\n" + "=" * 60 puts "FluentIcons Usage Report" puts "=" * 60 puts "Files scanned: #{@files_scanned}" puts "Unique icons found: #{icons.count}" puts "=" * 60 puts "\nIcons:" icons.each { |icon| puts " - #{icon}" } puts "=" * 60 + "\n" end |
#scan ⇒ Object
Scan all files and return found icons
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/fluent-icons/scanner.rb', line 16 def scan @icons_found.clear @files_scanned = 0 @paths.each do |path| if Dir.exist?(path) scan_directory(path) elsif File.exist?(path) scan_file(path) else warn "[FluentIcons::Scanner] Path not found: #{path}" if @verbose end end @icons_found.to_a.sort end |