Class: Beagle::Examples

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

Instance Method Summary collapse

Constructor Details

#initializeExamples

Returns a new instance of Examples.



5
6
7
# File 'lib/beagle/examples.rb', line 5

def initialize
  @entries = Hash.new{|hash, key|hash[key] = []}
end

Instance Method Details

#add(example) ⇒ Object



9
10
11
# File 'lib/beagle/examples.rb', line 9

def add(example)
  @entries[example.file_path] << [example.full_description, 0]
end

#durationObject



34
35
36
# File 'lib/beagle/examples.rb', line 34

def duration
  @duration ||= files.inject(0) {|sum, example| sum + example.last}
end

#examples(file_path) ⇒ Object



26
27
28
# File 'lib/beagle/examples.rb', line 26

def examples(file_path)
  @entries[file_path].sort {|a,b|b.last <=> a.last}
end

#filesObject



17
18
19
20
21
22
23
24
# File 'lib/beagle/examples.rb', line 17

def files
  files = []
  @entries.each do |file, examples|
    time = examples.inject(0) {|sum, example| sum + example.last}
    files << [file, examples.size, time]
  end
  files.sort {|a,b|b.last <=> a.last}
end

#set_time(example, time) ⇒ Object



13
14
15
# File 'lib/beagle/examples.rb', line 13

def set_time(example, time)
  @entries[example.file_path].last[1] = (time < 0 ? 0 : time)
end

#sizeObject



30
31
32
# File 'lib/beagle/examples.rb', line 30

def size
  @size ||= @entries.values.size
end