Class: Deplate::Listings

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(deplate) ⇒ Listings

Returns a new instance of Listings.



193
194
195
196
# File 'lib/deplate/counters.rb', line 193

def initialize(deplate)
    @deplate  = deplate
    @listings = {}
end

Instance Attribute Details

#listingsObject

Returns the value of attribute listings.



191
192
193
# File 'lib/deplate/counters.rb', line 191

def listings
  @listings
end

Instance Method Details

#def_listing(name, init = nil, props = nil) ⇒ Object



198
199
200
201
202
203
204
205
206
# File 'lib/deplate/counters.rb', line 198

def def_listing(name, init=nil, props=nil)
    init  ||= []
    props ||= {}
    @listings[name] = {
        :value => init, 
        :init  => init,
        :props => props,
    }
end

#eachObject



212
213
214
215
216
# File 'lib/deplate/counters.rb', line 212

def each
    @listings.each do |key, val|
        yield(key, val)
    end
end

#get(name, compound = false) ⇒ Object



218
219
220
221
222
223
224
225
226
227
228
229
230
# File 'lib/deplate/counters.rb', line 218

def get(name, compound=false)
    c = @listings[name]
    if c
        if compound
            c
        else
            c[:value]
        end
    else
        Deplate::Core.log(['Unknown list', name], :error)
        nil
    end
end

#get_prop(name, prop) ⇒ Object



240
241
242
243
244
245
246
247
248
# File 'lib/deplate/counters.rb', line 240

def get_prop(name, prop)
    c = @listings[name]
    if c
        c[:props][prop]
    else
        Deplate::Core.log(['Unknown list', name], :error)
        nil
    end
end

#is_defined?(name) ⇒ Boolean

Returns:

  • (Boolean)


208
209
210
# File 'lib/deplate/counters.rb', line 208

def is_defined?(name)
    @listings.keys.include?(name)
end

#push(name, value) ⇒ Object



250
251
252
253
254
255
# File 'lib/deplate/counters.rb', line 250

def push(name, value)
    c = get(name)
    if c
        c << value
    end
end

#reset(name = nil) ⇒ Object



257
258
259
260
261
262
263
264
265
266
267
268
# File 'lib/deplate/counters.rb', line 257

def reset(name=nil)
    if name
        c = get(name, true)
        if c
            set(name, c[:init])
        end
    else
        for name in @listings.keys
            reset(name)
        end
    end
end

#set(name, value, compound = false) ⇒ Object



232
233
234
235
236
237
238
# File 'lib/deplate/counters.rb', line 232

def set(name, value, compound=false)
    if compound
        @listings[name] = value
    else
        @listings[name][:value] = value
    end
end