Class: MarkdownExec::SavedAsset

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

Overview

SavedAsset

This class provides utilities to format and derive asset names based on given parameters. The ‘script_name` method derives a name for a script based on filename, prefix, time, and blockname. Similarly, the `stdout_name` method derives a name for stdout redirection.

Constant Summary collapse

DEFAULT_FTIME =
'%F-%H-%M-%S'
FILE_BLOCK_SEP =
','
JOIN_STR =
'_'
MARK_STR =
'~'

Instance Method Summary collapse

Constructor Details

#initialize(saved_asset_format:, blockname: nil, exts: nil, filename: nil, ftime: DEFAULT_FTIME, join_str: nil, mark: nil, prefix: nil, time: nil) ⇒ SavedAsset

Returns a new instance of SavedAsset.

Parameters:

  • filename (String) (defaults to: nil)

    the name of the file

  • prefix (String) (defaults to: nil)

    the prefix to use

  • time (Time) (defaults to: nil)

    the time object for formatting

  • blockname (String) (defaults to: nil)

    the block name to include

  • ftime (String) (defaults to: DEFAULT_FTIME)

    the time format (default: DEFAULT_FTIME)

  • exts (String) (defaults to: nil)

    the extension to append (default: ‘.sh’)



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/saved_assets.rb', line 29

def initialize(
  saved_asset_format:, blockname: nil, exts: nil,
  filename: nil, ftime: DEFAULT_FTIME, join_str: nil,
  mark: nil, prefix: nil, time: nil
)
  @filename = filename.present? ? filename.pub_name : '*'
  @prefix = prefix || '*'
  @time = time ? time.strftime(ftime) : '*'
  @blockname = blockname ? blockname.pub_name : '*'
  @exts = exts || '.*'
  @mark = mark || MARK_STR
  @join_str = join_str || JOIN_STR
  @saved_asset_format = saved_asset_format
end

Instance Method Details

#generate_nameString

Generates a formatted name based on the provided parameters.

Returns:

  • (String)

    the generated formatted name



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/saved_assets.rb', line 47

def generate_name
  # !!ey ({saved_asset_format: @saved_asset_format, blockname: @blockname, exts: @exts, filename: @filename, join: @join_str, mark: @mark, prefix: @prefix, time: @time })
  format(
    @saved_asset_format,
    {
      blockname: @blockname,
      exts: @exts,
      filename: @filename,
      join: @join_str,
      mark: @mark,
      prefix: @prefix,
      time: @time
    }
  )
end