Class: EhbrsRubyUtils::Videos::Resolution
- Inherits:
-
Object
- Object
- EhbrsRubyUtils::Videos::Resolution
- Includes:
- Comparable
- Defined in:
- lib/ehbrs_ruby_utils/videos/resolution.rb
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #higher ⇒ Object
- #lower ⇒ Object
- #pixels ⇒ Object
- #quality_to_s ⇒ Object
- #resolution_to_s ⇒ Object
- #to_s ⇒ Object
- #to_xs ⇒ Object
- #valid? ⇒ Boolean
Class Method Details
.valid_dimension?(dimension) ⇒ 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 |
#higher ⇒ Object
28 29 30 |
# File 'lib/ehbrs_ruby_utils/videos/resolution.rb', line 28 def higher [width, height].max end |
#lower ⇒ Object
32 33 34 |
# File 'lib/ehbrs_ruby_utils/videos/resolution.rb', line 32 def lower [width, height].min end |
#pixels ⇒ Object
36 37 38 |
# File 'lib/ehbrs_ruby_utils/videos/resolution.rb', line 36 def pixels width * height end |
#quality_to_s ⇒ Object
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_s ⇒ Object
44 45 46 |
# File 'lib/ehbrs_ruby_utils/videos/resolution.rb', line 44 def resolution_to_s "#{width}x#{height}" end |
#to_s ⇒ Object
48 49 50 |
# File 'lib/ehbrs_ruby_utils/videos/resolution.rb', line 48 def to_s resolution_to_s end |
#to_xs ⇒ Object
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
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 |