Module: Apdown

Defined in:
lib/apdown.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.parse_regex(type) ⇒ Object



3
4
5
# File 'lib/apdown.rb', line 3

def self.parse_regex(type)
  /(\{#{type}_(\d{1,2})_?(\w+)?\})/i
end

Instance Method Details

#text_unused_content(all_files, type, preselected = []) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/apdown.rb', line 13

def text_unused_content(all_files, type, preselected = [])
  all_numbers = []
  all_files.each_with_index { |a, i| all_numbers << i+1 }

  unused_numbers = all_numbers - (text_used_content(type)+preselected)

  unused_files = []
  all_files.each_with_index do |a, i|
    unused_files << a if unused_numbers.include?(i+1)
  end
  unused_files
end

#text_unused_data_filesObject



38
39
40
# File 'lib/apdown.rb', line 38

def text_unused_data_files
  text_unused_content(assets.only_data_files, 'file')
end

#text_unused_imagesObject



30
31
32
# File 'lib/apdown.rb', line 30

def text_unused_images
  text_unused_content(assets.only_images, 'img', respond_to?(:apdown_preselect) && apdown_preselect || [])
end

#text_used_content(type) ⇒ Object



7
8
9
10
11
# File 'lib/apdown.rb', line 7

def text_used_content(type)
  (apdown_text || '').scan(Apdown.parse_regex(type)).each_with_object([]) do |match, used_numbers|
    used_numbers << match[1].to_i
  end
end

#text_used_data_filesObject



34
35
36
# File 'lib/apdown.rb', line 34

def text_used_data_files
  text_used_content('file')
end

#text_used_imagesObject



26
27
28
# File 'lib/apdown.rb', line 26

def text_used_images
  text_used_content('img')
end