Sha256: 81ab9da854aa4f26865ff5387269ed15cbee7bc9dfca39d946dffb4c89877afd

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

# typed: strict
# frozen_string_literal: true

module Ffprober
  class Parser
    extend T::Sig

    sig { params(file_to_parse: String).returns(Ffprober::Wrapper) }
    def self.from_file(file_to_parse)
      check_version

      raise EmptyInput, file_to_parse if File.zero?(file_to_parse)

      file_parser = Parsers::FileParser.new(file_to_parse)
      json_parser = file_parser.load
      Ffprober::Wrapper.new(json_parser.json)
    end

    sig { params(url_to_parse: T.untyped).returns(Ffprober::Wrapper) }
    def self.from_url(url_to_parse)
      check_version

      url_parser = Parsers::UrlParser.new(url_to_parse)
      json_parser = url_parser.load
      Ffprober::Wrapper.new(json_parser.json)
    end

    sig { params(json_to_parse: T.untyped).returns(Ffprober::Wrapper) }
    def self.from_json(json_to_parse)
      json_parser = Parsers::JsonParser.new(json_to_parse)
      Ffprober::Wrapper.new(json_parser.json)
    end

    sig { returns(NilClass) }
    def self.check_version
      msg = "found version: #{FfprobeVersion.version}"
      raise UnsupportedVersion, msg if FfprobeVersion.invalid?
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ffprober-1.0 lib/ffprober/parser.rb