Class: Ptf::DataFile
- Inherits:
-
Object
- Object
- Ptf::DataFile
- Defined in:
- lib/ptf/data_file.rb
Constant Summary collapse
- DIR_PATH =
Ptf::FileSystem.data_dir
Instance Method Summary collapse
-
#data_file_path ⇒ String
Returns the full path to the data file.
-
#header_string ⇒ String
Returns the header string for the file.
-
#initialize(metadata_file) ⇒ DataFile
constructor
Initialize a new DataFile.
-
#write_to_file ⇒ Object
Write the header string to the data file.
Constructor Details
#initialize(metadata_file) ⇒ DataFile
Initialize a new DataFile.
11 12 13 14 15 |
# File 'lib/ptf/data_file.rb', line 11 def initialize() raise ArgumentError, "Metadata file not given." unless .is_a? Ptf::MetadataFile = end |
Instance Method Details
#data_file_path ⇒ String
Returns the full path to the data file.
20 21 22 |
# File 'lib/ptf/data_file.rb', line 20 def data_file_path File.join(DIR_PATH, .hash) end |
#header_string ⇒ String
Returns the header string for the file.
27 28 29 |
# File 'lib/ptf/data_file.rb', line 27 def header_string "##{@metadata_file.group.abbreviation}--#{@metadata_file.id} #{@metadata_file.title}\n#Due: #{@metadata_file.due_date_str}\n#Estimate: #{@metadata_file.estimate}\n\n\n" end |
#write_to_file ⇒ Object
Write the header string to the data file. Overwrites any data file for the same task.
32 33 34 35 36 |
# File 'lib/ptf/data_file.rb', line 32 def write_to_file File.open(data_file_path, "w") do |f| f.write header_string end end |