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
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 |
#higher ⇒ Object
31 32 33 |
# File 'lib/ehbrs_ruby_utils/videos/resolution.rb', line 31 def higher [width, height].max end |
#lower ⇒ Object
35 36 37 |
# File 'lib/ehbrs_ruby_utils/videos/resolution.rb', line 35 def lower [width, height].min end |
#pixels ⇒ Object
39 40 41 |
# File 'lib/ehbrs_ruby_utils/videos/resolution.rb', line 39 def pixels width * height end |
#quality_to_s ⇒ Object
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_s ⇒ Object
47 48 49 |
# File 'lib/ehbrs_ruby_utils/videos/resolution.rb', line 47 def resolution_to_s "#{width}x#{height}" end |
#to_s ⇒ Object
51 52 53 |
# File 'lib/ehbrs_ruby_utils/videos/resolution.rb', line 51 def to_s resolution_to_s end |
#to_xs ⇒ Object
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
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 |