Class: ArTTY

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

Defined Under Namespace

Classes: Art, Cache, Error, Generator, SystemInfo

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeArTTY

Returns a new instance of ArTTY.



48
49
50
51
52
53
54
55
56
57
58
59
60
61
# 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

Instance Attribute Details

#artObject (readonly)

Returns the value of attribute art.



2
3
4
# File 'lib/arTTY.rb', line 2

def art
  @art
end

Class Method Details

.current_versionObject



8
9
10
11
12
13
# 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

Instance Method Details

#cache(download = false) ⇒ Object



4
5
6
# File 'lib/arTTY.rb', line 4

def cache(download = false)
    @cache.refresh(download)
end

#exclude(pattern) ⇒ Object



15
16
17
18
19
# File 'lib/arTTY.rb', line 15

def exclude(pattern)
    @art.delete_if do |name|
        name.match(/#{pattern}/)
    end
end

#fits(width, height) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# 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) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# 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) ⇒ Object



63
64
65
66
67
# File 'lib/arTTY.rb', line 63

def match(pattern)
    @art.keep_if do |name|
        name.match(/#{pattern}/)
    end
end

#randomObject



69
70
71
# File 'lib/arTTY.rb', line 69

def random
    return @art.shuffle[0]
end