Class: Ptf::DataFile

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

Constant Summary collapse

DIR_PATH =
Ptf::FileSystem.data_dir

Instance Method Summary collapse

Constructor Details

#initialize(metadata_file) ⇒ DataFile

Initialize a new DataFile.

Parameters:

Raises:

  • (ArgumntError)

    if a MetadataFile is not given.



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_pathString

Returns the full path to the data file.

Returns:

  • (String)

    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_stringString

Returns the header string for the file.

Returns:

  • (String)

    the header string for the data 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_fileObject

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