Class: Rfd::Preview::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/rfd/preview/request.rb

Overview

Value object representing a preview generation request

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, file_path:, file_type:, width:, height:) ⇒ Request

Returns a new instance of Request.



9
10
11
12
13
14
15
16
# File 'lib/rfd/preview/request.rb', line 9

def initialize(id:, file_path:, file_type:, width:, height:)
  @id = id
  @file_path = file_path
  @file_type = file_type
  @width = width
  @height = height
  @timestamp = Time.now.to_f
end

Instance Attribute Details

#file_pathObject (readonly)

Returns the value of attribute file_path.



7
8
9
# File 'lib/rfd/preview/request.rb', line 7

def file_path
  @file_path
end

#file_typeObject (readonly)

Returns the value of attribute file_type.



7
8
9
# File 'lib/rfd/preview/request.rb', line 7

def file_type
  @file_type
end

#heightObject (readonly)

Returns the value of attribute height.



7
8
9
# File 'lib/rfd/preview/request.rb', line 7

def height
  @height
end

#idObject (readonly)

Returns the value of attribute id.



7
8
9
# File 'lib/rfd/preview/request.rb', line 7

def id
  @id
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



7
8
9
# File 'lib/rfd/preview/request.rb', line 7

def timestamp
  @timestamp
end

#widthObject (readonly)

Returns the value of attribute width.



7
8
9
# File 'lib/rfd/preview/request.rb', line 7

def width
  @width
end

Class Method Details

.from_hash(hash) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/rfd/preview/request.rb', line 29

def self.from_hash(hash)
  new(
    id: hash['id'],
    file_path: hash['path'],
    file_type: hash['file_type'] && hash['file_type'].to_sym,
    width: hash['width'],
    height: hash['height']
  )
end

Instance Method Details

#to_hObject



18
19
20
21
22
23
24
25
26
27
# File 'lib/rfd/preview/request.rb', line 18

def to_h
  {
    type: 'request',
    id: @id,
    path: @file_path,
    file_type: @file_type,
    width: @width,
    height: @height
  }
end