Class: Reviser::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/reviser/result.rb

Overview

This class represents an analysis result It allows us to easily output well-formatted results for certain output formats  (eg HTML)

 @author Renan Strauss

Instance Method Summary collapse

Constructor Details

#initialize(data = nil) ⇒ Result

In case no call to manufacture was made,  Checker will create a result with the same valeu for all formats



37
38
39
40
41
42
43
# File 'lib/reviser/result.rb', line 37

def initialize data = nil
	if data != nil
		Cfg[:out_format].each do |format|
			instance_variable_set("@#{format}".to_sym, data)
		end
	end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object

Does the magic ;-)  When the user calls a method whose name is a valid format,  we associate it with the given block value if a block is given,  else we return the stored value

Raises:

  • (NoMethodError)


51
52
53
54
55
56
57
# File 'lib/reviser/result.rb', line 51

def method_missing m, *args, &block
	raise NoMethodError, "Unknown format #{m}" unless Cfg::OUT_FORMATS.include?(m)

	format = "@#{m}".to_sym

	block_given? && instance_variable_set(format, block[]) || instance_variable_get(format)
end