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)


13
14
15
# File 'lib/ehbrs_ruby_utils/videos/resolution.rb', line 13

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

Instance Method Details

#<=>(other) ⇒ Object



20
21
22
23
24
25
# File 'lib/ehbrs_ruby_utils/videos/resolution.rb', line 20

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

  higher <=> other.higher
end

#higherObject



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

def higher
  [width, height].max
end

#lowerObject



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

def lower
  [width, height].min
end

#pixelsObject



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

def pixels
  width * height
end

#quality_to_sObject



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

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

#resolution_to_sObject



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

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

#to_sObject



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

def to_s
  resolution_to_s
end

#to_xsObject



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

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

#valid?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/ehbrs_ruby_utils/videos/resolution.rb', line 55

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