Class: FormatParser::ActiveStorage::BlobAnalyzer

Inherits:
Object
  • Object
show all
Defined in:
lib/active_storage/blob_analyzer.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(blob) ⇒ BlobAnalyzer

Returns a new instance of BlobAnalyzer.



17
18
19
# File 'lib/active_storage/blob_analyzer.rb', line 17

def initialize(blob)
  @blob = blob
end

Class Method Details

.accept?(_blob) ⇒ Boolean, true

Format parser is able to handle a lot of format so by default it will accept all files

Returns:

  • (Boolean, true)

    always return true



13
14
15
# File 'lib/active_storage/blob_analyzer.rb', line 13

def self.accept?(_blob)
  true
end

Instance Method Details

#metadataHash

Returns file metadatas.

Returns:

  • (Hash)

    file metadatas



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/active_storage/blob_analyzer.rb', line 22

def 
  io = BlobIO.new(@blob)
  parsed_file = FormatParser.parse(io)

  if parsed_file
    # We symbolize keys because of existing output hash format of ImageAnalyzer
    parsed_file.as_json.symbolize_keys
  else
    logger.info "Skipping file analysis because FormatParser doesn't support the file"
  end
end