Class: RandomAdapter

Inherits:
Adapter show all
Includes:
Logging
Defined in:
lib/business/adapter/random_adapter.rb

Overview

Self implementation from Adapter class to make it works with a Random Phrase Generator

Author:

  • Daniel Machado Fernandez

Version:

  • 1.0

Constant Summary

Constants included from Logging

Logging::KermitPFC

Instance Method Summary collapse

Methods included from Logging

#logger, logger

Constructor Details

#initializeRandomAdapter

Initializes the Random Adapter class with the dao parameters



15
16
17
18
19
# File 'lib/business/adapter/random_adapter.rb', line 15

def initialize
	
	@dao = DAO.new 'rpg'

end

Instance Method Details

#connect_stream(stream = 1) ⇒ Object

Connects to a Random Phrase Generator and retrieves phrases

Parameters:

  • stream (Integer) (defaults to: 1)

    number of the stream



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/business/adapter/random_adapter.rb', line 25

def connect_stream (stream=1)

	logger.info('Starting Random adapter')
	random = RandomPhraseGenerator.new
	i=0
	while true
		
		persist random.generate

		i = i+1
		if i%10 == 0
			sleep 10
		end
		
	end

end

#persist(status) ⇒ Object

Save the status in a database to release the execution charge of threat that info in real time

Parameters:

  • status (String)

    the status to persist



46
47
48
# File 'lib/business/adapter/random_adapter.rb', line 46

def persist status
	@dao.save_status status
end