Class: JsDuck::Img::Dir

Inherits:
Object
  • Object
show all
Defined in:
lib/jsduck/img/dir.rb

Overview

Looks up images from a directory.

Instance Method Summary collapse

Constructor Details

#initialize(full_path, relative_path) ⇒ Dir

Returns a new instance of Dir.



9
10
11
12
13
# File 'lib/jsduck/img/dir.rb', line 9

def initialize(full_path, relative_path)
  @full_path = full_path
  @relative_path = relative_path
  @images = {}
end

Instance Method Details

#all_usedObject

Returns all used images.



34
35
36
# File 'lib/jsduck/img/dir.rb', line 34

def all_used
  @images.values
end

#get(filename) ⇒ Object

Retrieves hash of information for a given relative image filename. It will have the fields:

  • :filename - the same as the parameter of this method

  • :full_path - actual path in the filesystem.

  • :relative_path - relative path to be used inside <img> tag.

  • :width - Image width

  • :height - Image height

When the image is not found, returns nil.



25
26
27
28
29
30
31
# File 'lib/jsduck/img/dir.rb', line 25

def get(filename)
  img = scan_img(filename)
  if img
    @images[filename] = img
  end
  img
end

#report_unusedObject

Print warnings about all unused images.



39
40
41
# File 'lib/jsduck/img/dir.rb', line 39

def report_unused
  scan_for_unused_images.each {|img| warn_unused(img) }
end