Class: Tamarillo::TomatoFile

Inherits:
Object
  • Object
show all
Defined in:
lib/tamarillo/tomato_file.rb

Overview

Internal: Represents a tomato in the filesystem.

Constant Summary collapse

FILENAME_FORMAT =
'%Y%m%d%H%M%S'
PATH_FORMAT =
'%Y/%m%d'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tomato) ⇒ TomatoFile

Public: Initializes a new tomato file.

tomato - A Tomato instance to serialize.



12
13
14
# File 'lib/tamarillo/tomato_file.rb', line 12

def initialize(tomato)
  @tomato = tomato
end

Class Method Details

.path(time) ⇒ Object

Public: Generate a path from a time.

time - A Tomato’s start time Date.

Returns A String path generated from a Date.



31
32
33
34
35
36
# File 'lib/tamarillo/tomato_file.rb', line 31

def self.path(time)
  dir = time.strftime(PATH_FORMAT)
  name = time.strftime(FILENAME_FORMAT)

  "#{dir}/#{name}"
end

Instance Method Details

#contentObject

Public: Returns the serialized form of a Tomato.



39
40
41
# File 'lib/tamarillo/tomato_file.rb', line 39

def content
  [time,task,state].join("\n")
end

#nameObject

Public; Returns the filename of the Tomato.



17
18
19
# File 'lib/tamarillo/tomato_file.rb', line 17

def name
  @tomato.started_at.strftime(FILENAME_FORMAT)
end

#pathObject

Public: Returns a String path to the Tomato.



22
23
24
# File 'lib/tamarillo/tomato_file.rb', line 22

def path
  self.class.path(@tomato.started_at)
end