class ArTTY

Attributes

art[R]

Public Class Methods

current_version() click to toggle source
# File lib/arTTY.rb, line 8
def self.current_version
    __FILE__.match(/arTTY-(\d+\.\d+\.\d+)/) do |m|
        return m[1]
    end
    return "error" # Shouldn't happen
end
new() click to toggle source
# File lib/arTTY.rb, line 48
def initialize
    @cache = ArTTY::Cache.new

    @@all_art ||= Array.new
    @cache.art.each do |name|
        @@all_art.push(name)
    end

    @@all_art.sort! do |a, b|
        a.downcase <=> b.downcase
    end

    @art = @@all_art.clone
end

Public Instance Methods

cache(download = false) click to toggle source
# File lib/arTTY.rb, line 4
def cache(download = false)
    @cache.refresh(download)
end
exclude(pattern) click to toggle source
# File lib/arTTY.rb, line 15
def exclude(pattern)
    @art.delete_if do |name|
        name.match(/#{pattern}/)
    end
end
fits(width, height) click to toggle source
# File lib/arTTY.rb, line 21
def fits(width, height)
    if ((height <= 0) || (width <= 0))
        @art.clear
    else
        @art.keep_if do |name|
            (@cache.get_height_for(name) <= height) &&
            (@cache.get_width_for(name) <= width)
        end
    end
end
get(name, sysinfo = nil) click to toggle source
# File lib/arTTY.rb, line 32
def get(name, sysinfo = nil)
    case name
    when "none"
        img = ArTTY::Art.new
    else
        if (!@@all_art.include?(name))
            raise ArTTY::Error::ArtNotFound.new(name)
        end
        file = @cache.get_file_for(name)
        file = nil if (!@art.include?(name))
        img = ArTTY::Art.new(file)
    end
    img.sysinfo = sysinfo
    return img
end
match(pattern) click to toggle source
# File lib/arTTY.rb, line 63
def match(pattern)
    @art.keep_if do |name|
        name.match(/#{pattern}/)
    end
end
random() click to toggle source
# File lib/arTTY.rb, line 69
def random
    return @art.shuffle[0]
end