Class: TwtxtFile

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

Instance Method Summary collapse

Constructor Details

#initialize(file_path) ⇒ TwtxtFile

Returns a new instance of TwtxtFile.



4
5
6
7
8
9
10
11
12
# File 'lib/twtxt/file.rb', line 4

def initialize(file_path)
  @file_path = file_path
  @entries = []

  File.foreach(@file_path) do |line|
    entry = Twtxt.parse(line.strip)
    @entries << entry if entry
  end
end

Instance Method Details

#add_entry(entry) ⇒ Object



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

def add_entry(entry)
  @entries << entry
end

#entriesObject



14
15
16
# File 'lib/twtxt/file.rb', line 14

def entries
  @entries
end

#writeObject



22
23
24
25
26
27
28
# File 'lib/twtxt/file.rb', line 22

def write
  File.open(@file_path, "w") do |file|
    @entries.each do |entry|
      file.puts(Twtxt.format(entry))
    end
  end
end