Class: Hakoy::TimestampPath
- Inherits:
-
Object
- Object
- Hakoy::TimestampPath
- Defined in:
- lib/hakoy/timestamp_path.rb
Constant Summary collapse
- DIR_PARTS_FOR =
{ day: %w(year month), hour: %w(year month day) }
- TWO_DIGITS_FORMAT =
'%02d'
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ TimestampPath
constructor
A new instance of TimestampPath.
- #to_path(timestamp_str) ⇒ Object (also: #call)
Constructor Details
#initialize(opts = {}) ⇒ TimestampPath
Returns a new instance of TimestampPath.
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/hakoy/timestamp_path.rb', line 12 def initialize(opts={}) unit = opts.fetch(:unit) { :day } span = opts.fetch(:span) { 1 } @dir_strategy = -> (t) do DIR_PARTS_FOR[unit].map { |m| t.send(m) }.join('/') end @file_strategy = -> (t) do TWO_DIGITS_FORMAT % (t.send(unit) / span).to_i end end |
Instance Method Details
#to_path(timestamp_str) ⇒ Object Also known as: call
25 26 27 |
# File 'lib/hakoy/timestamp_path.rb', line 25 def to_path() build_path Time.parse() end |