Class: S3DataPacker::FilenameGenerator
- Inherits:
-
Object
- Object
- S3DataPacker::FilenameGenerator
- Defined in:
- lib/s3_data_packer/filename_generator.rb
Instance Attribute Summary collapse
-
#number ⇒ Object
readonly
Returns the value of attribute number.
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
-
#splitter ⇒ Object
readonly
Returns the value of attribute splitter.
Instance Method Summary collapse
- #datestamp ⇒ Object
- #generate! ⇒ Object
-
#initialize(opts = {}) ⇒ FilenameGenerator
constructor
A new instance of FilenameGenerator.
- #prefix ⇒ Object
- #suffix ⇒ Object
- #timecode_dec ⇒ Object
- #timecode_int ⇒ Object
- #timestamp ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ FilenameGenerator
Returns a new instance of FilenameGenerator.
5 6 7 8 9 10 11 12 |
# File 'lib/s3_data_packer/filename_generator.rb', line 5 def initialize opts={} @number = opts[:start_at] || 1 @prefix = opts[:prefix] || [:prefix] @suffix = opts[:suffix] || [:suffix] @pattern = opts[:pattern] || [:pattern] @splitter = opts[:splitter] || [:splitter] validate_pattern! end |
Instance Attribute Details
#number ⇒ Object (readonly)
Returns the value of attribute number.
3 4 5 |
# File 'lib/s3_data_packer/filename_generator.rb', line 3 def number @number end |
#pattern ⇒ Object (readonly)
Returns the value of attribute pattern.
3 4 5 |
# File 'lib/s3_data_packer/filename_generator.rb', line 3 def pattern @pattern end |
#splitter ⇒ Object (readonly)
Returns the value of attribute splitter.
3 4 5 |
# File 'lib/s3_data_packer/filename_generator.rb', line 3 def splitter @splitter end |
Instance Method Details
#datestamp ⇒ Object
18 |
# File 'lib/s3_data_packer/filename_generator.rb', line 18 def datestamp; Time.now.strftime('%Y%m%d'); end |
#generate! ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/s3_data_packer/filename_generator.rb', line 22 def generate! name = pattern.map{ |key| send(key) } name.delete_if { |value| value.nil? || value == '' } name = name.map(&:to_s).join(splitter) @number += 1 name end |
#prefix ⇒ Object
19 |
# File 'lib/s3_data_packer/filename_generator.rb', line 19 def prefix; @prefix; end |
#suffix ⇒ Object
20 |
# File 'lib/s3_data_packer/filename_generator.rb', line 20 def suffix; @suffix; end |
#timecode_dec ⇒ Object
15 |
# File 'lib/s3_data_packer/filename_generator.rb', line 15 def timecode_dec; Time.now.to_f; end |
#timecode_int ⇒ Object
14 |
# File 'lib/s3_data_packer/filename_generator.rb', line 14 def timecode_int; Time.now.to_i; end |
#timestamp ⇒ Object
17 |
# File 'lib/s3_data_packer/filename_generator.rb', line 17 def ; Time.now.strftime('%Y%m%d%H%M%s'); end |