class Edj::Journal

Attributes

tree[R]

Public Class Methods

new(f) click to toggle source
# File lib/edj/base.rb, line 31
def initialize(f)
        @f = f
        @tree = {}
end

Public Instance Methods

filter(type) click to toggle source
# File lib/edj/base.rb, line 36
def filter(type)
        File.open(@f).readlines
                .map {|line| Item.from(JSON.parse(line))}
                .select {|item| item.is_a? type }
end
scan_value() click to toggle source
# File lib/edj/base.rb, line 42
def scan_value()
        total_value = 0
        File.open(@f).each do |line|
                item = Item.from(JSON.parse(line))
                if item.is_a? ScanItem then
                        v = item.value
                        bits = item.bodyName.split(' ')
                        (1..(bits.size-1)).each do |i|
                                entry = bits[0..i].join(' ')
                                o = @tree[entry]
                                @tree[entry] ||= 0
                                @tree[entry] += v
                        end
                        STDOUT.puts("#{item.timestamp} #{item.bodyName} --> #{v}")
                        total_value = total_value + v
                end
        end
        total_value
end