Sha256: 6a73a017dbec6a2ef9d9de5c52a1a4d910feb7057349f332b992ba4d616bf72c
Contents?: true
Size: 1.28 KB
Versions: 13
Compression:
Stored size: 1.28 KB
Contents
# frozen_string_literal: true require 'eac_ruby_utils/core_ext' require 'ehbrs_ruby_utils/videos/quality' module EhbrsRubyUtils module Videos class Resolution enable_simple_cache include ::Comparable class << self def valid_dimension?(dimension) dimension.is_a?(::Integer) && dimension.positive? end end common_constructor :width, :height def <=>(other) r = (lower <=> other.lower) return r unless r.zero? higher <=> other.higher end def to_xs [quality_to_s, resolution_to_s].join(' / ') end def higher [width, height].max end def lower [width, height].min end def pixels width * height end def quality_to_s quality.if_present('?', &:to_s) end def resolution_to_s "#{width}x#{height}" end def to_s resolution_to_s end def valid? [width, height].all? { |d| self.class.valid_dimension?(d) } end private def quality_uncached ::EhbrsRubyUtils::Videos::Quality.list .find { |quality| quality.resolution_match?(self) } || raise("No quality matches resolution #{resolution}") end end end end
Version data entries
13 entries across 13 versions & 1 rubygems