Class: Avm::Result
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Avm::Result
- Includes:
- EacRubyUtils::Listable
- Defined in:
- lib/avm/result.rb
Defined Under Namespace
Classes: Error
Constant Summary collapse
- TYPE_SUCCESS_COLOR =
'green'
- TYPE_ERROR_COLOR =
'red'
- TYPE_NEUTRAL_COLOR =
'light_black'
- TYPE_PENDING_COLOR =
'yellow'
- TYPE_OUTDATED_COLOR =
'blue'
Instance Attribute Summary collapse
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
-
.success_or_error(success, success_value, error_value = nil) ⇒ Avm::Result
Return Avm::Result.success(success_value) if
success
is truthy.
Instance Method Summary collapse
-
#initialize(value, type) ⇒ Result
constructor
A new instance of Result.
- #label ⇒ Object
- #label_bg ⇒ Object
- #label_fg ⇒ Object
- #type_color ⇒ Object
Constructor Details
#initialize(value, type) ⇒ Result
Returns a new instance of Result.
40 41 42 43 44 |
# File 'lib/avm/result.rb', line 40 def initialize(value, type) super(value) validate_type(type) @type = type end |
Instance Attribute Details
#type ⇒ Object (readonly)
Returns the value of attribute type.
38 39 40 |
# File 'lib/avm/result.rb', line 38 def type @type end |
Class Method Details
.success_or_error(success, success_value, error_value = nil) ⇒ Avm::Result
Return Avm::Result.success(success_value) if success
is truthy. Return Avm::Result.error(error_value || success_value) if success
is falsely.
29 30 31 32 33 34 35 |
# File 'lib/avm/result.rb', line 29 def success_or_error(success, success_value, error_value = nil) if success self.success(success_value) else error(error_value.presence || success_value) end end |
Instance Method Details
#label ⇒ Object
46 47 48 |
# File 'lib/avm/result.rb', line 46 def label label_fg end |
#label_bg ⇒ Object
54 55 56 |
# File 'lib/avm/result.rb', line 54 def label_bg ColorizedString.new(to_s).light_white.send("on_#{type_color}") end |
#label_fg ⇒ Object
50 51 52 |
# File 'lib/avm/result.rb', line 50 def label_fg ColorizedString.new(to_s).send(type_color) end |
#type_color ⇒ Object
58 59 60 |
# File 'lib/avm/result.rb', line 58 def type_color self.class.const_get("type_#{type}_color".upcase) end |