Class: ConvenientService::Examples::Standard::V1::DateTime::Services::SafeParse
- Inherits:
-
Object
- Object
- ConvenientService::Examples::Standard::V1::DateTime::Services::SafeParse
- Includes:
- Service::Configs::Standard::V1
- Defined in:
- lib/convenient_service/examples/standard/v1/date_time/services/safe_parse.rb
Instance Attribute Summary collapse
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#string ⇒ Object
readonly
Returns the value of attribute string.
Instance Method Summary collapse
-
#initialize(string:, format:) ⇒ SafeParse
constructor
A new instance of SafeParse.
- #result ⇒ Object
Constructor Details
#initialize(string:, format:) ⇒ SafeParse
Returns a new instance of SafeParse.
14 15 16 17 |
# File 'lib/convenient_service/examples/standard/v1/date_time/services/safe_parse.rb', line 14 def initialize(string:, format:) @string = string @format = format end |
Instance Attribute Details
#format ⇒ Object (readonly)
Returns the value of attribute format.
12 13 14 |
# File 'lib/convenient_service/examples/standard/v1/date_time/services/safe_parse.rb', line 12 def format @format end |
#string ⇒ Object (readonly)
Returns the value of attribute string.
12 13 14 |
# File 'lib/convenient_service/examples/standard/v1/date_time/services/safe_parse.rb', line 12 def string @string end |
Instance Method Details
#result ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/convenient_service/examples/standard/v1/date_time/services/safe_parse.rb', line 19 def result success(date_time: ::DateTime.strptime(string, format)) rescue ::Date::Error => exception failure( data: {exception: exception}, message: "Failed to parse `DateTime` object from `#{string}` with `#{format}`" ) end |