Class: InboxFromFile

Inherits:
Inbox show all
Defined in:
lib/inbox_persistence.rb

Constant Summary

Constants included from Status

Status::ACTIVE_STATES, Status::INACTIVE_STATES, Status::STATUS_ORDER, Status::STATUS_SYMBOLS, Status::SYMBOLS_STATUS

Instance Attribute Summary collapse

Attributes inherited from Context

#actions, #name

Instance Method Summary collapse

Methods inherited from Inbox

#include?

Methods inherited from Context

#<<, #delete, #include?, #to_s

Methods included from Status

#active, #directory_name, #inactive, #index, #symbol, #with_status

Constructor Details

#initialize(file_name) ⇒ InboxFromFile



3
4
5
# File 'lib/inbox_persistence.rb', line 3

def initialize(file_name)
  @file_name = file_name
end

Instance Attribute Details

#entriesObject (readonly)

Returns the value of attribute entries.



2
3
4
# File 'lib/inbox_persistence.rb', line 2

def entries
  @entries
end

Instance Method Details

#empty!Object



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

def empty!
  @entries = []
end

#readObject



9
10
11
12
13
14
15
16
17
# File 'lib/inbox_persistence.rb', line 9

def read
  content = File.exists?(@file_name) ? read_and_decode(@file_name):''
  @entries = []
  content.each_line do |line| 
    line.strip!
    @entries << line unless line.empty?
  end
  #log @entries        
end

#writeObject

log @entries



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

def write
  File.open(@file_name,"w") {} if File.exists?(@file_name) if @entries.empty?    
end