Class: GlTail::Config

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



110
111
112
113
114
# File 'lib/gl_tail/config.rb', line 110

def initialize
  @sources = []
  @blocks = []
  @max_size = 1.0
end

Instance Attribute Details

#sourcesObject (readonly)

Returns the value of attribute sources.



108
109
110
# File 'lib/gl_tail/config.rb', line 108

def sources
  @sources
end

Class Method Details

.parse_yaml(file) ⇒ Object



101
102
103
104
105
# File 'lib/gl_tail/config.rb', line 101

def parse_yaml(file)
  require 'yaml'

  YamlParser.new(file).apply(self.new)
end

Instance Method Details

#add_activity(source, options = { }) ⇒ Object

block, message, size



162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/gl_tail/config.rb', line 162

def add_activity(source, options = { })

  if block = @blocks_by_name[options[:block]]

    size = screen.min_blob_size
    if options[:size]
      size = options[:size].to_f

      options[:real_size] = size
      @max_size = size if size > @max_size
      options[:size] = screen.min_blob_size + ((size / @max_size) * (screen.max_blob_size - screen.min_blob_size))
    end

    block.add_activity({
                         :name => source.name,
                         :color => source.color,
                         :size => screen.min_blob_size
                       }.update(options) )
  end
end

#add_block(name) ⇒ Object



124
125
126
127
# File 'lib/gl_tail/config.rb', line 124

def add_block(name)
  @blocks << b = Block.new(self, name)
  b
end

#add_event(source, options = { }) ⇒ Object

block, message



184
185
186
187
188
# File 'lib/gl_tail/config.rb', line 184

def add_event(source, options = { })
  if block = @blocks_by_name[options[:block]]
    block.add_event( { :name => source.name, :color => source.color, :size => screen.min_blob_size}.update(options) )
  end
end

#blocksObject



120
121
122
# File 'lib/gl_tail/config.rb', line 120

def blocks
  @blocks
end

#do_processObject



134
135
136
137
138
139
140
141
142
143
# File 'lib/gl_tail/config.rb', line 134

def do_process
  active = 0

  sources.each do |it|
    active += 1
    it.process
  end

  active
end

#initObject



151
152
153
154
155
156
157
158
159
# File 'lib/gl_tail/config.rb', line 151

def init
  sources.each { |it| it.init }

  @blocks_by_name = {}

  blocks.each do |it|
    @blocks_by_name[it.name] = it
  end
end

#reshape(w, h) ⇒ Object



129
130
131
132
# File 'lib/gl_tail/config.rb', line 129

def reshape(w, h)
  screen.aspect = h.to_f / w.to_f
  screen.window_width, screen.window_height = w, h
end

#screenObject



116
117
118
# File 'lib/gl_tail/config.rb', line 116

def screen
  @screen ||= Screen.new(self)
end

#updateObject



145
146
147
148
149
# File 'lib/gl_tail/config.rb', line 145

def update
  sources.each { |it| it.update }
  blocks.each { |it| it.update }
  @max_size = @max_size * 0.99 if(@max_size * 0.99 > 1.0)
end