Module: NattyUI::WithStatus

Included in:
ProgressHelper, Section, Task
Defined in:
lib/natty-ui/element.rb

Overview

Methods for elements with status like ProgressHelper, Section, Task.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#active?true, false (readonly)

Returns whether the element is still active.

Returns:

  • (true, false)

    whether the element is still active



62
# File 'lib/natty-ui/element.rb', line 62

def active? = @status.nil?

#closed?true, false (readonly)

Returns whether the element is completed.

Returns:

  • (true, false)

    whether the element is completed



66
# File 'lib/natty-ui/element.rb', line 66

def closed? = !active?

#failed?true, false (readonly)

Returns whether the element is completed with failure.

Returns:

  • (true, false)

    whether the element is completed with failure



74
# File 'lib/natty-ui/element.rb', line 74

def failed? = @state == :failed

#statusSymbol? (readonly)

Returns element's current status.

Returns:

  • (Symbol, nil)

    element's current status



58
59
60
# File 'lib/natty-ui/element.rb', line 58

def status
  @status
end

Instance Method Details

#failed(*text) {|failed| ... } ⇒ Features

Close the element with a failure.

Parameters:

  • text (#to_s)

    optional message

Yields:

  • optionally, when block is given

Yield Parameters:

Returns:



95
96
97
98
99
100
101
102
103
104
105
# File 'lib/natty-ui/element.rb', line 95

def failed(*text, &block)
  return self if @state
  if text.empty?
    super(@title, &block).ok if @title
  else
    super.ok
  end
  @state = :failed
  _failed
  self.end
end

#ok(*text) ⇒ Features Also known as: done

Close the element.

Parameters:

  • text (#to_s)

    optional message

Returns:



80
81
82
83
84
85
86
# File 'lib/natty-ui/element.rb', line 80

def ok(*text)
  return self if @state
  text = [@title] if text.empty? && @title
  _done(text)
  @state = :ok
  self.end
end

#ok?true, false

Returns whether the element is completed.

Returns:

  • (true, false)

    whether the element is completed



70
# File 'lib/natty-ui/element.rb', line 70

def ok? = @state == :ok