Class: EhbrsRubyUtils::Videos::Resolution

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/ehbrs_ruby_utils/videos/resolution.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.valid_dimension?(dimension) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/ehbrs_ruby_utils/videos/resolution.rb', line 10

def valid_dimension?(dimension)
  dimension.is_a?(::Integer) && dimension.positive?
end

Instance Method Details

#<=>(other) ⇒ Object



17
18
19
20
21
22
# File 'lib/ehbrs_ruby_utils/videos/resolution.rb', line 17

def <=>(other)
  r = (lower <=> other.lower)
  return r unless r.zero?

  higher <=> other.higher
end

#higherObject



28
29
30
# File 'lib/ehbrs_ruby_utils/videos/resolution.rb', line 28

def higher
  [width, height].max
end

#lowerObject



32
33
34
# File 'lib/ehbrs_ruby_utils/videos/resolution.rb', line 32

def lower
  [width, height].min
end

#pixelsObject



36
37
38
# File 'lib/ehbrs_ruby_utils/videos/resolution.rb', line 36

def pixels
  width * height
end

#quality_to_sObject



40
41
42
# File 'lib/ehbrs_ruby_utils/videos/resolution.rb', line 40

def quality_to_s
  quality.if_present('?', &:to_s)
end

#resolution_to_sObject



44
45
46
# File 'lib/ehbrs_ruby_utils/videos/resolution.rb', line 44

def resolution_to_s
  "#{width}x#{height}"
end

#to_sObject



48
49
50
# File 'lib/ehbrs_ruby_utils/videos/resolution.rb', line 48

def to_s
  resolution_to_s
end

#to_xsObject



24
25
26
# File 'lib/ehbrs_ruby_utils/videos/resolution.rb', line 24

def to_xs
  [quality_to_s, resolution_to_s].join(' / ')
end

#valid?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/ehbrs_ruby_utils/videos/resolution.rb', line 52

def valid?
  [width, height].all? { |d| self.class.valid_dimension?(d) }
end