Class: Bitmovin::Encoding::Encodings::Thumbnail
- Defined in:
- lib/bitmovin/encoding/encodings/thumbnails/thumbnail.rb
Instance Attribute Summary collapse
-
#height ⇒ Object
Returns the value of attribute height.
-
#outputs ⇒ Object
Returns the value of attribute outputs.
-
#pattern ⇒ Object
Returns the value of attribute pattern.
-
#positions ⇒ Object
Returns the value of attribute positions.
-
#unit ⇒ Object
Returns the value of attribute unit.
Attributes inherited from Resource
#created_at, #description, #id, #modified_at, #name
Instance Method Summary collapse
- #errors ⇒ Object
-
#initialize(encoding_id, stream_id, hash = {}) ⇒ Thumbnail
constructor
A new instance of Thumbnail.
- #invalid? ⇒ Boolean
- #save! ⇒ Object
- #valid? ⇒ Boolean
- #validate! ⇒ Object
Methods inherited from Resource
#delete!, find, init, #init_instance, #inspect, list, #persisted?
Methods included from Helpers
#camelize_hash, #hash_to_struct, result, #result, #underscore_hash
Constructor Details
#initialize(encoding_id, stream_id, hash = {}) ⇒ Thumbnail
Returns a new instance of Thumbnail.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/bitmovin/encoding/encodings/thumbnails/thumbnail.rb', line 4 def initialize(encoding_id, stream_id, hash = {}) @errors = [] init_instance(File.join('/v1/encoding/encodings', encoding_id, 'streams', stream_id, 'thumbnails')) @encoding_id = encoding_id @stream_id = stream_id hsh = ActiveSupport::HashWithIndifferentAccess.new(underscore_hash(hash)) @positions = hsh[:positions] || [] @unit = hsh[:unit] @height = hsh[:height] @pattern = hsh[:pattern] @outputs = (hsh[:outputs] || []).map { |output| Bitmovin::Encoding::StreamOutput.new(output) } end |
Instance Attribute Details
#height ⇒ Object
Returns the value of attribute height.
19 20 21 |
# File 'lib/bitmovin/encoding/encodings/thumbnails/thumbnail.rb', line 19 def height @height end |
#outputs ⇒ Object
Returns the value of attribute outputs.
19 20 21 |
# File 'lib/bitmovin/encoding/encodings/thumbnails/thumbnail.rb', line 19 def outputs @outputs end |
#pattern ⇒ Object
Returns the value of attribute pattern.
19 20 21 |
# File 'lib/bitmovin/encoding/encodings/thumbnails/thumbnail.rb', line 19 def pattern @pattern end |
#positions ⇒ Object
Returns the value of attribute positions.
19 20 21 |
# File 'lib/bitmovin/encoding/encodings/thumbnails/thumbnail.rb', line 19 def positions @positions end |
#unit ⇒ Object
Returns the value of attribute unit.
19 20 21 |
# File 'lib/bitmovin/encoding/encodings/thumbnails/thumbnail.rb', line 19 def unit @unit end |
Instance Method Details
#errors ⇒ Object
27 28 29 |
# File 'lib/bitmovin/encoding/encodings/thumbnails/thumbnail.rb', line 27 def errors @errors end |
#invalid? ⇒ Boolean
40 41 42 |
# File 'lib/bitmovin/encoding/encodings/thumbnails/thumbnail.rb', line 40 def invalid? !valid? end |
#save! ⇒ Object
21 22 23 24 25 |
# File 'lib/bitmovin/encoding/encodings/thumbnails/thumbnail.rb', line 21 def save! if valid? super end end |
#valid? ⇒ Boolean
31 32 33 34 35 36 37 38 |
# File 'lib/bitmovin/encoding/encodings/thumbnails/thumbnail.rb', line 31 def valid? validate! unless @errors.empty? puts errors return false end true end |
#validate! ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/bitmovin/encoding/encodings/thumbnails/thumbnail.rb', line 44 def validate! @errors = [] if @positions.nil? || @positions.empty? @errors << 'There has to be at least one position for a thumbnail' end if @height.nil? || @height <= 0 @errors << 'The height has to be set and must be greater than 0' end if @pattern.nil? || @pattern.blank? @errors << 'The pattern has to be set and must not be blank' end unless ['SECONDS', 'PERCENTS', nil].include? @unit @errors << "The unit can only be 'SECONDS' or 'PERCENTS'" end @outputs.each do |output| @errors << output.errors unless output.valid? end @errors.flatten! end |