Class: TinyPng::Path

Inherits:
Object
  • Object
show all
Defined in:
lib/tiny_png/path.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*show) ⇒ Path

Create a TinyPng::Path object and optionally add .png paths to the show list (also transverses directories).



7
8
9
10
# File 'lib/tiny_png/path.rb', line 7

def initialize *show
  @show = TinyPng::Path.get_all show
  @blacklist = []
end

Class Method Details

.get_all(*list) ⇒ Object

Get all .png path names from the passed-in files and directories.



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/tiny_png/path.rb', line 52

def self.get_all *list
  list.flatten.uniq.collect do |path|
    if path.is_a?(TinyPng::Path)
      path.list
    else
      if File.directory?(path)
        Dir.glob("#{path.gsub(/\/$/,'')}/**/*.png")
      else
        path.downcase.match(/\.png$/) ? path : nil
      end
    end
  end.flatten.uniq.compact
end

Instance Method Details

#add(*list) ⇒ Object

Add paths to the list (also transverses directories).



15
16
17
# File 'lib/tiny_png/path.rb', line 15

def add *list
  @show = (@show + TinyPng::Path.get_all(list)).uniq
end

#blacklist(*list) ⇒ Object

Add paths to the list (also transverses directories). The blacklist supercedes the add list, such that any path added to the blacklist will not show up in the final compilation.



24
25
26
# File 'lib/tiny_png/path.rb', line 24

def blacklist *list
  @blacklist = (@blacklist + TinyPng::Path.get_all(list)).uniq
end

#listObject

Return the full list of paths, minus anything in the blacklist.



45
46
47
# File 'lib/tiny_png/path.rb', line 45

def list
  @show.uniq - @blacklist
end

#remove_from_blacklist(*list) ⇒ Object

Remove paths from the blacklist (also transverses directories).



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

def remove_from_blacklist *list
  @blacklist = @blacklist - TinyPng::Path.get_all(list)
end

#remove_from_list(*list) ⇒ Object

Remove paths from the list (also transverses directories).



31
32
33
# File 'lib/tiny_png/path.rb', line 31

def remove_from_list *list
  @show = @show - TinyPng::Path.get_all(list)
end