Class: Worklog::Services::NewWorklog
- Defined in:
- lib/worklog/services/new_worklog.rb
Overview
This service creates timelog file in the working directory.
and returns name of the created file '<folder_name>.timelog'
If file with this name exits
Constant Summary collapse
- LOGCONTENT =
<<~EOF title %s hourly_rate 20 date_format '%%Y-%%m-%%d' track '%s', spent: '1h', task: 'created timelog ..' EOF
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(logname) ⇒ NewWorklog
constructor
A new instance of NewWorklog.
Methods inherited from Service
Constructor Details
#initialize(logname) ⇒ NewWorklog
Returns a new instance of NewWorklog.
25 26 27 |
# File 'lib/worklog/services/new_worklog.rb', line 25 def initialize(logname) @logname = logname end |
Instance Method Details
#call ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/worklog/services/new_worklog.rb', line 15 def call filename = @logname + Worklog::LOGMASK[1..-1] if File.exist? filename puts "Operation canceled. File with name '#{filename}' already exists" return '' end File.write(filename, LOGCONTENT % [@logname, Date.today.to_s]) filename end |