class Ptf::DataFile

Constants

DIR_PATH

Public Class Methods

new(metadata_file) click to toggle source

Initialize a new DataFile.

@param metadata_file [Ptf::MetadataFile] the associated metadata file.

@raise [ArgumntError] if a MetadataFile is not given.

# File lib/ptf/data_file.rb, line 11
def initialize(metadata_file)
  raise ArgumentError, "Metadata file not given." unless metadata_file.is_a? Ptf::MetadataFile

  @metadata_file = metadata_file
end

Public Instance Methods

data_file_path() click to toggle source

Returns the full path to the data file.

@return [String] the full path to the data file.

# File lib/ptf/data_file.rb, line 20
def data_file_path
  File.join(DIR_PATH, @metadata_file.hash)
end
header_string() click to toggle source

Returns the header string for the file.

@return [String] the header string for the data file.

# 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() click to toggle source

Write the header string to the data file. Overwrites any data file for the same task.

# 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