Class: Israeli::Result
- Inherits:
-
Object
- Object
- Israeli::Result
- Defined in:
- lib/israeli/result.rb
Overview
Result object returned by parse methods.
Provides a rich object with validation status, original/normalized values, and formatting methods for a cleaner API than simple booleans.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#normalized ⇒ Object
readonly
Returns the value of attribute normalized.
-
#original ⇒ Object
readonly
Returns the value of attribute original.
-
#reason ⇒ Object
readonly
Returns the value of attribute reason.
Instance Method Summary collapse
-
#formatted ⇒ String?
The formatted value, or nil if invalid.
-
#initialize(original:, normalized:, valid:, reason: nil) ⇒ Result
constructor
A new instance of Result.
-
#invalid? ⇒ Boolean
True if the value is invalid.
-
#to_s ⇒ String
String representation.
-
#valid? ⇒ Boolean
True if the value is valid.
-
#value ⇒ String?
The normalized value (alias for formatted).
Constructor Details
#initialize(original:, normalized:, valid:, reason: nil) ⇒ Result
Returns a new instance of Result.
27 28 29 30 31 32 |
# File 'lib/israeli/result.rb', line 27 def initialize(original:, normalized:, valid:, reason: nil) @original = original @normalized = normalized @valid = valid @reason = reason end |
Instance Attribute Details
#normalized ⇒ Object (readonly)
Returns the value of attribute normalized.
21 22 23 |
# File 'lib/israeli/result.rb', line 21 def normalized @normalized end |
#original ⇒ Object (readonly)
Returns the value of attribute original.
21 22 23 |
# File 'lib/israeli/result.rb', line 21 def original @original end |
#reason ⇒ Object (readonly)
Returns the value of attribute reason.
21 22 23 |
# File 'lib/israeli/result.rb', line 21 def reason @reason end |
Instance Method Details
#formatted ⇒ String?
Returns The formatted value, or nil if invalid.
45 46 47 48 49 |
# File 'lib/israeli/result.rb', line 45 def formatted return nil unless valid? @normalized end |
#invalid? ⇒ Boolean
Returns true if the value is invalid.
40 41 42 |
# File 'lib/israeli/result.rb', line 40 def invalid? !@valid end |
#to_s ⇒ String
Returns String representation.
52 53 54 |
# File 'lib/israeli/result.rb', line 52 def to_s formatted || "" end |
#valid? ⇒ Boolean
Returns true if the value is valid.
35 36 37 |
# File 'lib/israeli/result.rb', line 35 def valid? @valid end |
#value ⇒ String?
Returns The normalized value (alias for formatted).
57 58 59 |
# File 'lib/israeli/result.rb', line 57 def value formatted end |