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
20
# File 'lib/business/adapter/random_adapter.rb', line 15

def initialize
	
	@dao = DAO.new 'rpg'
	logger.debug('Starting RandomAdapter...')

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



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

def connect_stream (stream=1)

	random = RandomPhraseGenerator.new
	i=0
	while true
		
		persist random.generate
		logger.debug('retrieving...')
		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