Class: CloudscrapeClient::Executions::Result::File

Inherits:
Object
  • Object
show all
Defined in:
lib/cloudscrape_client/executions/result/file.rb

Constant Summary collapse

ParseError =
Class.new(StandardError)
UnknownContentType =
Class.new(StandardError)
FILE_KEYWORD =
"FILE"
REGEX =
%r{
  \A                       # start of line
  #{FILE_KEYWORD}          # detector keywork
  :                        # detector vs content split
  (?'contentType'\w+\/\w+) # content type
  ;                        # first split
  (?'providerId'\d+)       # Dexi provider id
  ;                        # second split
  (?'id'[a-z0-9-]*)        # file id
  \Z                       # end of line
}x
EXPECTED_FORMAT =
"FILE:<CONTENT_TYPE>;<PROVIDER_ID>;<FILE_ID>"

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ File

Returns a new instance of File.



25
26
27
# File 'lib/cloudscrape_client/executions/result/file.rb', line 25

def initialize(value)
  @value = value
end

Instance Method Details

#content_typeObject



38
39
40
41
42
# File 'lib/cloudscrape_client/executions/result/file.rb', line 38

def content_type
  @content_type ||= MIME::Types[raw_content_type].first.tap do |result|
    raise UnknownContentType, raw_content_type if result.nil?
  end
end

#extensionObject



48
49
50
# File 'lib/cloudscrape_client/executions/result/file.rb', line 48

def extension
  content_type.preferred_extension
end

#file_nameObject



44
45
46
# File 'lib/cloudscrape_client/executions/result/file.rb', line 44

def file_name
  "#{id}-#{provider_id}.#{extension}"
end

#idObject



29
30
31
# File 'lib/cloudscrape_client/executions/result/file.rb', line 29

def id
  @id ||= find("id")
end

#provider_idObject



33
34
35
# File 'lib/cloudscrape_client/executions/result/file.rb', line 33

def provider_id
  @provider_id ||= find("providerId")
end