Class: AddressbookTxt

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename = 'addressbook.txt', path: '.') ⇒ AddressbookTxt

Returns a new instance of AddressbookTxt.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/addressbook_txt.rb', line 25

def initialize(filename='addressbook.txt', path: '.')
  
  @filename, @path = filename, path
  
  fpath = File.join(path, filename)
  
  if File.exists?(fpath) then

    @dx = import_to_dx(File.read(fpath))    
        
  else
    @dx = new_dx    
  end
end

Instance Attribute Details

#to_sObject (readonly)

Returns the value of attribute to_s.



23
24
25
# File 'lib/addressbook_txt.rb', line 23

def to_s
  @to_s
end

Instance Method Details

#dxObject



40
41
42
# File 'lib/addressbook_txt.rb', line 40

def dx()
  @dx
end

#save(filename = @filename) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/addressbook_txt.rb', line 44

def save(filename=@filename)

  s = File.basename(filename) + "\n" + dx_to_s(@dx).lines[1..-1].join
  File.write File.join(@path, filename), s
  @dx.save File.join(@path, filename.sub(/\.txt$/,'.xml'))
      
end