1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# web/lib/sources.rb
class Source
@@sources = Array.new
attr_reader :id, :name, :data_until, :update_start, :update_end, :visible, :dbsize, :dbpack
# Enumerate all available sources
def self.each
@@sources.each do |source|
yield source
end
end
# The number of available sources
def self.size
@@sources.size
end
def self.visible
@@sources.select{ |source| source.visible }
end
# Create new source
# id - Symbol with id for this source
# name - Name of this source
def initialize(id, name, data_until, update_start, update_end, visible)
@id = id.to_sym
@name = name
@data_until = data_until
@update_start = update_start
@update_end = update_end
@visible = visible
@dbsize = File.size("../../data/#{ dbname }").to_bytes rescue 0
@dbpack = File.size("../../download/#{ dbname }.bz2").to_bytes rescue 0
@@sources << self
end
# The URL where this source is described
def url
"/sources/#{ @id }"
end
# The img URL of this source
def imgurl(size=16)
"/img/sources/#{ @id }.#{ size }.png"
end
# Returns img tag for this source
def img(size=16, title_prefix='')
%Q{<img src="#{ imgurl(size) }" alt="#{ name }" title="#{title_prefix} #{ name }" tipsy="w" width="#{ size }" height="#{ size }"/>}
end
def dbname
"taginfo-#{ @id }.db"
end
def link_download
%Q{<a rel="nofollow" href="/download/#{ dbname }.bz2">#{ dbname }.bz2</a>}
end
end
|