Class: DTK::Client::TaskStatus::StreamMode::Element::Format

Inherits:
Hash
  • Object
show all
Defined in:
lib/task_status/stream_mode/element/format.rb

Constant Summary collapse

Settings =
{
  :task_start => {
  },
  :task_end => {
  },
  :stage => {
  },
  :stage_start => {
    :border_symbol      => '=',
  },
  :stage_end => {
    :border_symbol      => '-',
  },
  :default => {
    :border_symbol      => '=',
    :border_size        => 60,
    :bracket_symbol     => '=',
    :bracket_size       => 25,
    :duration_accuracy  => 1, # how many decimal places accuracy
    :include_start_time => true,
    :tab_size           => 2, # how many spaces each tab has
  }
}

Instance Method Summary collapse

Constructor Details

#initialize(type) ⇒ Format

Returns a new instance of Format.



44
45
46
47
48
# File 'lib/task_status/stream_mode/element/format.rb', line 44

def initialize(type)
  super()
  @type = type && type.to_sym
  replace(Settings[:default].merge(Settings[@type] || {}))
end

Instance Method Details

#borderObject



55
56
57
58
59
# File 'lib/task_status/stream_mode/element/format.rb', line 55

def border
  border_symbol = self[:border_symbol]
  border_size    = self[:border_size]
  "#{border_symbol * border_size}"
end

#duration_msg?(duration) ⇒ Boolean

Returns:

  • (Boolean)


73
74
75
76
77
# File 'lib/task_status/stream_mode/element/format.rb', line 73

def duration_msg?(duration)
  if formatted_duration = formatted_duration?(duration)
    "DURATION: #{formatted_duration}"
  end
end

#format(msg, params = {}) ⇒ Object



50
51
52
53
# File 'lib/task_status/stream_mode/element/format.rb', line 50

def format(msg, params = {})
  aug_msg = augment(msg, params)
  params[:bracket] ? bracket(aug_msg) : aug_msg
end

#formatted_duration?(duration) ⇒ Boolean

Returns:

  • (Boolean)


67
68
69
70
71
# File 'lib/task_status/stream_mode/element/format.rb', line 67

def formatted_duration?(duration)
  if duration
    "#{duration.round(self[:duration_accuracy])}s"
  end
end

#start_time_msg?(started_at) ⇒ Boolean

Returns:

  • (Boolean)


61
62
63
64
65
# File 'lib/task_status/stream_mode/element/format.rb', line 61

def start_time_msg?(started_at)
  if started_at
    "TIME START: #{started_at}"
  end
end