Class: CommandsFile

Inherits:
Object
  • Object
show all
Defined in:
lib/xmimerge/commands_file.rb

Constant Summary collapse

COMMAND_FILE_NAME =
"commands.merge"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCommandsFile

Returns a new instance of CommandsFile.



8
9
10
11
# File 'lib/xmimerge/commands_file.rb', line 8

def initialize
	@buffer = Array.new
	@log = App.logger
end

Instance Attribute Details

#commandsObject (readonly)

Returns the value of attribute commands.



6
7
8
# File 'lib/xmimerge/commands_file.rb', line 6

def commands
  @commands
end

Instance Method Details

#add_command_to_buffer(command) ⇒ Object



20
21
22
23
# File 'lib/xmimerge/commands_file.rb', line 20

def add_command_to_buffer(command)
	@log.debug "Command added to the buffer: \"#{command}\"."
	@buffer << command
end

#buffer_sizeObject



34
35
36
# File 'lib/xmimerge/commands_file.rb', line 34

def buffer_size
	@buffer.size
end

#has_command?(command) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
# File 'lib/xmimerge/commands_file.rb', line 25

def has_command?(command)			
	has = @commands.select {|c| c.include? command} 
	!has.empty?
end

#load_commandsObject



13
14
15
16
17
18
# File 'lib/xmimerge/commands_file.rb', line 13

def load_commands
	@log.info "Loading command file '#{COMMAND_FILE_NAME}'..."
	@commands = File.readlines(COMMAND_FILE_NAME, :encoding => "UTF-8")
	@log.info "Command file loaded."
	#@log.info "#{@commands.size} command(s)."
end

#remove_if_is_last_command(command) ⇒ Object



30
31
32
# File 'lib/xmimerge/commands_file.rb', line 30

def remove_if_is_last_command(command)
	@buffer.delete_at(@buffer.size-1) if @buffer.last == command
end

#save_bufferObject



38
39
40
41
42
43
44
# File 'lib/xmimerge/commands_file.rb', line 38

def save_buffer
	@log.debug "Buffer saved."
	f = File.new(COMMAND_FILE_NAME, "w")
	f.write(@buffer.join("\n"))
	@buffer = Array.new
	f.close unless f.closed?
end