Class: TwtxtFile
- Inherits:
-
Object
- Object
- TwtxtFile
- Defined in:
- lib/twtxt/file.rb
Instance Method Summary collapse
- #add_entry(entry) ⇒ Object
- #entries ⇒ Object
-
#initialize(file_path) ⇒ TwtxtFile
constructor
A new instance of TwtxtFile.
- #write ⇒ Object
Constructor Details
#initialize(file_path) ⇒ 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 |
#entries ⇒ Object
14 15 16 |
# File 'lib/twtxt/file.rb', line 14 def entries @entries end |
#write ⇒ Object
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 |