class ReVIEW::Book::ImageFinder

Public Class Methods

new(basedir, chapid, builder, exts) click to toggle source
# File ../../../../../lib/review/book/image_finder.rb, line 16
def initialize(basedir, chapid, builder, exts)
  @basedir = basedir
  @chapid = chapid
  @builder = builder
  @exts = exts
  @entries = get_entries()
end

Public Instance Methods

add_entry(path) click to toggle source
# File ../../../../../lib/review/book/image_finder.rb, line 28
def add_entry(path)
  unless @entries.include?(path)
    @entries << path
  end
  @entries
end
find_path(id) click to toggle source
# File ../../../../../lib/review/book/image_finder.rb, line 35
def find_path(id)
  targets = target_list(id)
  targets.each do |target|
    @exts.each do |ext|
      if @entries.include?("#{target}#{ext}")
        return "#{target}#{ext}"
      end
    end
  end
  nil
end
get_entries() click to toggle source
# File ../../../../../lib/review/book/image_finder.rb, line 24
def get_entries
  Dir.glob(File.join(@basedir, "**{,/*/**}/*.*")).uniq
end
target_list(id) click to toggle source
# File ../../../../../lib/review/book/image_finder.rb, line 47
def target_list(id)
  [
    # 1. <basedir>/<builder>/<chapid>/<id>.<ext>
    "#{@basedir}/#{@builder}/#{@chapid}/#{id}",

    # 2. <basedir>/<builder>/<chapid>-<id>.<ext>
    "#{@basedir}/#{@builder}/#{@chapid}-#{id}",

    # 3. <basedir>/<builder>/<id>.<ext>
    "#{@basedir}/#{@builder}/#{id}",

    # 4. <basedir>/<chapid>/<id>.<ext>
    "#{@basedir}/#{@chapid}/#{id}",

    # 5. <basedir>/<chapid>-<id>.<ext>
    "#{@basedir}/#{@chapid}-#{id}",

    # 6. <basedir>/<id>.<ext>
    "#{@basedir}/#{id}"
  ]
end