Sha256: e7b6ea76b87228fbd8d5efc6f6681aa9995853099d794273fe92e1398334092e
Contents?: true
Size: 1.3 KB
Versions: 71
Compression:
Stored size: 1.3 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 ? width : height end def lower width < height ? width : height 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
71 entries across 71 versions & 2 rubygems