Class: Noir::Command::New::Note
Constant Summary
collapse
- TimeFormat =
'%Y%m%d'
- FileNameGlob =
'[0-9]*_????????.txt'
- SerialDigitRange =
1..3
Class Method Summary
collapse
sub_commands
check_command_not_found, description, sub_commands
Class Method Details
.create_new_note ⇒ Object
23
24
25
26
27
28
|
# File 'lib/noir/command/new/note.rb', line 23
def create_new_note
note_num = Dir.glob(FileNameGlob).size + 1
note_name = serial_format(note_num) + '_' + Time.now.strftime(TimeFormat) + '.txt'
Noir::Command::New.createFile note_name
return note_name
end
|
.execute(*args) ⇒ Object
30
31
32
|
# File 'lib/noir/command/new/note.rb', line 30
def execute *args
puts create_new_note
end
|
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/noir/command/new/note.rb', line 10
def serial_format number
digit_from_env = ENV['NOIR_NOTE_SERIAL_DIGIT']
digit = digit_from_env.nil? ? 2 : digit_from_env.to_i
if SerialDigitRange.cover?(digit)
return format("%0#{digit}d", number)
else
raise ["Invalid NOIR_NOTE_SERIAL_DIGIT=#{digit_from_env}.",
"supported digits are [#{SerialDigitRange.to_a.join(', ')}]."].join("\n")
end
end
|