ehbrs_ruby_utils 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9c9c60e0e61be16ec0c161bf3b4d90f730801e7f6db236eb77ea9fd866064d84
4
+ data.tar.gz: 007b8112c7699c7558bc04a58a1b1a96ea3c6092c985f342a9d6af68006ea6de
5
+ SHA512:
6
+ metadata.gz: 13745fd4234de95f716e1403a2e18394b8db6fdb6a0440dd12038a08842f64c1b988c418466331e8a6c1540576b42ac112c68e69e8570a38414454f204e830e0
7
+ data.tar.gz: 5be54f132eb69c59096313862e0a3a5b332db85712aa818c8a53e66d714c40d19233da33eb1323cb33bc501ae28d9dd8763cb88c808d4754da857c9b89eba387
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EhbrsRubyUtils
6
+ require_sub __FILE__
7
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EhbrsRubyUtils
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EhbrsRubyUtils
6
+ module Videos
7
+ require_sub __FILE__
8
+ end
9
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EhbrsRubyUtils
6
+ module Videos
7
+ class Quality
8
+ enable_simple_cache
9
+ include ::Comparable
10
+
11
+ POSITIVE_MARGIN = 0.75
12
+ LIST = [240, 480, 720, 1080, 2160].freeze
13
+
14
+ class << self
15
+ enable_simple_cache
16
+
17
+ def by_height(height)
18
+ list.find { |v| v.height == height }
19
+ end
20
+
21
+ private
22
+
23
+ def list_uncached
24
+ preceding = nil
25
+ LIST.map { |height| preceding = new(height, preceding) }
26
+ end
27
+ end
28
+
29
+ attr_reader :following
30
+
31
+ common_constructor :height, :preceding do
32
+ preceding&.send('following=', self)
33
+ end
34
+
35
+ def <=>(other)
36
+ height <=> other.height
37
+ end
38
+
39
+ def to_s
40
+ height.to_s
41
+ end
42
+
43
+ def to_xs
44
+ "#{height} (Min: #{min_height}, Max: #{max_height})"
45
+ end
46
+
47
+ def resolution_match?(resolution)
48
+ (min_height.blank? || resolution.lower >= min_height) &&
49
+ (max_height.blank? || resolution.lower <= max_height)
50
+ end
51
+
52
+ private
53
+
54
+ attr_writer :following
55
+
56
+ def max_height_uncached
57
+ following.if_present do |v|
58
+ delta = v.height - height
59
+ height + (delta * POSITIVE_MARGIN).to_i
60
+ end
61
+ end
62
+
63
+ def min_height_uncached
64
+ preceding.if_present { |v| v.max_height + 1 }
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'ehbrs_ruby_utils/videos/quality'
5
+
6
+ module EhbrsRubyUtils
7
+ module Videos
8
+ class Resolution
9
+ enable_simple_cache
10
+ include ::Comparable
11
+
12
+ class << self
13
+ def valid_dimension?(dimension)
14
+ dimension.is_a?(::Integer) && dimension.positive?
15
+ end
16
+ end
17
+
18
+ common_constructor :width, :height
19
+
20
+ def <=>(other)
21
+ r = (lower <=> other.lower)
22
+ return r unless r.zero?
23
+
24
+ higher <=> other.higher
25
+ end
26
+
27
+ def to_xs
28
+ [quality_to_s, resolution_to_s].join(' / ')
29
+ end
30
+
31
+ def higher
32
+ width > height ? width : height
33
+ end
34
+
35
+ def lower
36
+ width < height ? width : height
37
+ end
38
+
39
+ def pixels
40
+ width * height
41
+ end
42
+
43
+ def quality_to_s
44
+ quality.if_present('?', &:to_s)
45
+ end
46
+
47
+ def resolution_to_s
48
+ "#{width}x#{height}"
49
+ end
50
+
51
+ def to_s
52
+ resolution_to_s
53
+ end
54
+
55
+ def valid?
56
+ [width, height].all? { |d| self.class.valid_dimension?(d) }
57
+ end
58
+
59
+ private
60
+
61
+ def quality_uncached
62
+ ::EhbrsRubyUtils::Videos::Quality.list
63
+ .find { |quality| quality.resolution_match?(self) } ||
64
+ raise("No quality matches resolution #{resolution}")
65
+ end
66
+ end
67
+ end
68
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ehbrs_ruby_utils
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Eduardo H. Bogoni
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-06-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: eac_ruby_utils
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.36'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.36'
27
+ - !ruby/object:Gem::Dependency
28
+ name: eac_ruby_gem_support
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.1'
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 0.1.1
37
+ type: :development
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '0.1'
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 0.1.1
47
+ description:
48
+ email:
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - lib/ehbrs_ruby_utils.rb
54
+ - lib/ehbrs_ruby_utils/version.rb
55
+ - lib/ehbrs_ruby_utils/videos.rb
56
+ - lib/ehbrs_ruby_utils/videos/quality.rb
57
+ - lib/ehbrs_ruby_utils/videos/resolution.rb
58
+ homepage:
59
+ licenses: []
60
+ metadata: {}
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project:
77
+ rubygems_version: 2.7.7
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: Utilities for EHB/RS's Ruby projects.
81
+ test_files: []