Class: Bors

Inherits:
Object
  • Object
show all
Defined in:
lib/bors.rb,
lib/bors/math.rb,
lib/bors/result.rb,
lib/bors/example.rb,
lib/bors/exceptions.rb,
lib/bors/command_line.rb,
lib/bors/result/samples.rb,
lib/bors/example/feature.rb,
lib/bors/result/settings.rb,
lib/bors/result/statistics.rb

Defined Under Namespace

Modules: Exceptions, Math Classes: CommandLine, Example, Result

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Bors

Returns a new instance of Bors.



12
13
14
15
16
# File 'lib/bors.rb', line 12

def initialize(options)
	raise Exceptions::ArgumentError.new('You must specify an examples file') unless options[:examples_file]
	@options = options
	@examples_file = File.new(options[:examples_file], 'a')
end

Instance Attribute Details

#examplesObject (readonly)

returns the examples as a string in VW format



28
29
30
# File 'lib/bors.rb', line 28

def examples
  @examples
end

Instance Method Details

#add_example(details) ⇒ Object



18
19
20
# File 'lib/bors.rb', line 18

def add_example(details)
	@examples_file.write("#{Example.new(details).to_s}\n")
end

#get_example(at) ⇒ Object

returns an example from the file



23
24
25
# File 'lib/bors.rb', line 23

def get_example(at)
	get_line_from_file(@examples_file, at) # should convert to Example class instead of String
end

#run!(run_options = {}) ⇒ Object

Runs vowpal wabbit with the loaded examples



35
36
37
38
39
40
41
42
43
# File 'lib/bors.rb', line 35

def run!(run_options={})
	with_closed_examples_file do
		raise Exceptions::MissingExamples.new unless File.open(@examples_file.path, 'r').readlines.count > 0
		run_options.merge!({:examples => @examples_file.path})
		out = CommandLine.new(run_options).run!
		FileUtils.rm(@examples_file.path) if @options[:temp_examples] == true
		return Result.new(out)
	end
end