Module: Aperitiiif::Assets

Included in:
Batch
Defined in:
lib/aperitiiif/batch/assets.rb

Overview

TO DO COMMENT

Instance Method Summary collapse

Instance Method Details

#asset_map(dir = config.source_dir) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/aperitiiif/batch/assets.rb', line 23

def asset_map(dir = config.source_dir)
  map = {}
  Dir["#{dir}/*"].each do |path|
    parent_id       = Utils.parent_id(path, dir)
    children        = child_assets path
    map[parent_id]  = children unless children.empty?
  end
  map
end

#assetsObject



7
8
9
# File 'lib/aperitiiif/batch/assets.rb', line 7

def assets
  @assets ||= map_to_assets
end

#child_assets(path) ⇒ Object



11
12
13
14
15
16
# File 'lib/aperitiiif/batch/assets.rb', line 11

def child_assets(path)
  return [path] if Utils.valid_source?(path)
  return [] unless File.directory? path

  Dir.glob("#{path}/*").select { |sub| Utils.valid_source? sub }
end

#map_to_assets(mymap = asset_map) ⇒ Object

has smell :reek:NestedIterators



19
20
21
# File 'lib/aperitiiif/batch/assets.rb', line 19

def map_to_assets(mymap = asset_map)
  mymap.flat_map { |id, vals| vals.map { |val| Asset.new id, val, config } }
end