Class: Rfd::Preview::Result
- Inherits:
-
Object
- Object
- Rfd::Preview::Result
- Defined in:
- lib/rfd/preview/result.rb
Overview
Value object representing a preview generation result
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#file_type ⇒ Object
readonly
Returns the value of attribute file_type.
-
#lines ⇒ Object
readonly
Returns the value of attribute lines.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#request_id ⇒ Object
readonly
Returns the value of attribute request_id.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#thumbnail_path ⇒ Object
readonly
Returns the value of attribute thumbnail_path.
Class Method Summary collapse
- .cancelled(request_id:) ⇒ Object
- .error(request_id:, error:) ⇒ Object
- .from_hash(hash) ⇒ Object
- .success(request_id:, file_type:, lines: nil, thumbnail_path: nil, metadata: nil) ⇒ Object
Instance Method Summary collapse
- #cancelled? ⇒ Boolean
- #error? ⇒ Boolean
-
#initialize(request_id:, status:, file_type: nil, lines: nil, thumbnail_path: nil, metadata: nil, error: nil) ⇒ Result
constructor
A new instance of Result.
- #success? ⇒ Boolean
- #to_h ⇒ Object
Constructor Details
#initialize(request_id:, status:, file_type: nil, lines: nil, thumbnail_path: nil, metadata: nil, error: nil) ⇒ Result
Returns a new instance of Result.
9 10 11 12 13 14 15 16 17 |
# File 'lib/rfd/preview/result.rb', line 9 def initialize(request_id:, status:, file_type: nil, lines: nil, thumbnail_path: nil, metadata: nil, error: nil) @request_id = request_id @status = status.to_sym @file_type = file_type && file_type.to_sym @lines = lines @thumbnail_path = thumbnail_path = @error = error end |
Instance Attribute Details
#error ⇒ Object (readonly)
Returns the value of attribute error.
7 8 9 |
# File 'lib/rfd/preview/result.rb', line 7 def error @error end |
#file_type ⇒ Object (readonly)
Returns the value of attribute file_type.
7 8 9 |
# File 'lib/rfd/preview/result.rb', line 7 def file_type @file_type end |
#lines ⇒ Object (readonly)
Returns the value of attribute lines.
7 8 9 |
# File 'lib/rfd/preview/result.rb', line 7 def lines @lines end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
7 8 9 |
# File 'lib/rfd/preview/result.rb', line 7 def end |
#request_id ⇒ Object (readonly)
Returns the value of attribute request_id.
7 8 9 |
# File 'lib/rfd/preview/result.rb', line 7 def request_id @request_id end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
7 8 9 |
# File 'lib/rfd/preview/result.rb', line 7 def status @status end |
#thumbnail_path ⇒ Object (readonly)
Returns the value of attribute thumbnail_path.
7 8 9 |
# File 'lib/rfd/preview/result.rb', line 7 def thumbnail_path @thumbnail_path end |
Class Method Details
.cancelled(request_id:) ⇒ Object
65 66 67 |
# File 'lib/rfd/preview/result.rb', line 65 def self.cancelled(request_id:) new(request_id: request_id, status: :cancelled) end |
.error(request_id:, error:) ⇒ Object
61 62 63 |
# File 'lib/rfd/preview/result.rb', line 61 def self.error(request_id:, error:) new(request_id: request_id, status: :error, error: error) end |
.from_hash(hash) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/rfd/preview/result.rb', line 45 def self.from_hash(hash) new( request_id: hash['id'], status: hash['status'], file_type: hash['file_type'], lines: hash['lines'], thumbnail_path: hash['thumbnail_path'], metadata: hash['metadata'], error: hash['error'] ) end |
.success(request_id:, file_type:, lines: nil, thumbnail_path: nil, metadata: nil) ⇒ Object
57 58 59 |
# File 'lib/rfd/preview/result.rb', line 57 def self.success(request_id:, file_type:, lines: nil, thumbnail_path: nil, metadata: nil) new(request_id: request_id, status: :success, file_type: file_type, lines: lines, thumbnail_path: thumbnail_path, metadata: ) end |
Instance Method Details
#cancelled? ⇒ Boolean
27 28 29 |
# File 'lib/rfd/preview/result.rb', line 27 def cancelled? @status == :cancelled end |
#error? ⇒ Boolean
23 24 25 |
# File 'lib/rfd/preview/result.rb', line 23 def error? @status == :error end |
#success? ⇒ Boolean
19 20 21 |
# File 'lib/rfd/preview/result.rb', line 19 def success? @status == :success end |
#to_h ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rfd/preview/result.rb', line 31 def to_h hash = { type: 'result', id: @request_id, status: @status.to_s } hash[:file_type] = @file_type.to_s if @file_type hash[:lines] = @lines if @lines hash[:thumbnail_path] = @thumbnail_path if @thumbnail_path hash[:metadata] = if hash[:error] = @error if @error hash end |