Class: XCRes::ResourcesAnalyzer::XCAssetsAnalyzer

Inherits:
BaseResourcesAnalyzer show all
Defined in:
lib/xcres/analyzer/resources_analyzer/xcassets_analyzer.rb

Overview

A XCAssetsAnalyzer scans the project for asset catalogs, which should be included in the output file.

Constant Summary

Constants inherited from BaseResourcesAnalyzer

BaseResourcesAnalyzer::FILTER_WORDS

Instance Attribute Summary

Attributes inherited from Analyzer

#exclude_file_patterns, #logger, #options, #sections, #target

Instance Method Summary collapse

Methods inherited from BaseResourcesAnalyzer

#build_images_section_data, #build_section_data, #filter_device_specific_image_paths, #find_files_in_dir, #find_image_files, #key_from_path

Methods inherited from Analyzer

#filter_exclusions, #find_file_refs_by_extname, #initialize, #is_file_ref_included_in_application_target?, #new_section, #project, #resources_files

Methods included from FileHelper

#basename_without_ext

Constructor Details

This class inherits a constructor from XCRes::Analyzer

Instance Method Details

#analyzeObject



12
13
14
15
# File 'lib/xcres/analyzer/resources_analyzer/xcassets_analyzer.rb', line 12

def analyze
  @sections = build_sections_for_xcassets
  super
end

#build_section_for_xcassets(bundle) ⇒ Section

Build a section for a asset catalog

Parameters:

  • xcassets_bundle (XCAssets::Bundle)

    the file reference to the resources bundle file

Returns:



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/xcres/analyzer/resources_analyzer/xcassets_analyzer.rb', line 43

def build_section_for_xcassets bundle
  log "Found asset catalog %s with #%s image files.",
    bundle.path.basename, bundle.resources.count

  section_name = "#{basename_without_ext(bundle.path)}Assets"
  section_data = build_images_section_data(bundle.resources.map(&:path), {
    use_basename:     [:path],
    path_without_ext: true
  })
  new_section(section_name, section_data)
end

#build_sections_for_xcassetsArray<Section>

Build a section for each asset catalog if it contains any resources

Returns:

  • (Array<Section>)

    the built sections



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/xcres/analyzer/resources_analyzer/xcassets_analyzer.rb', line 22

def build_sections_for_xcassets
  file_refs = find_file_refs_by_extname '.xcassets'

  log "Found #%s asset catalogs in project.", file_refs.count

  file_refs.map do |file_ref|
    bundle = XCAssets::Bundle.open(file_ref.real_path)
    section = build_section_for_xcassets(bundle)
    log 'Add section for %s with %s elements', section.name, section.items.count unless section.nil?
    section
  end.compact
end