Class: S3DataPacker::FilenameGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/s3_data_packer/filename_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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] || default_options[:prefix]
  @suffix = opts[:suffix] || default_options[:suffix]
  @pattern = opts[:pattern] || default_options[:pattern]
  @splitter = opts[:splitter] || default_options[:splitter]
  validate_pattern!
end

Instance Attribute Details

#numberObject (readonly)

Returns the value of attribute number.



3
4
5
# File 'lib/s3_data_packer/filename_generator.rb', line 3

def number
  @number
end

#patternObject (readonly)

Returns the value of attribute pattern.



3
4
5
# File 'lib/s3_data_packer/filename_generator.rb', line 3

def pattern
  @pattern
end

#splitterObject (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

#datestampObject



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

#prefixObject



19
# File 'lib/s3_data_packer/filename_generator.rb', line 19

def prefix; @prefix; end

#suffixObject



20
# File 'lib/s3_data_packer/filename_generator.rb', line 20

def suffix; @suffix; end

#timecode_decObject



15
# File 'lib/s3_data_packer/filename_generator.rb', line 15

def timecode_dec; Time.now.to_f; end

#timecode_intObject



14
# File 'lib/s3_data_packer/filename_generator.rb', line 14

def timecode_int; Time.now.to_i; end

#timestampObject



17
# File 'lib/s3_data_packer/filename_generator.rb', line 17

def timestamp; Time.now.strftime('%Y%m%d%H%M%s'); end