class Bitmovin::Encoding::Encodings::Sprite

Attributes

distance[RW]
height[RW]
outputs[RW]
sprite_name[RW]
vtt_name[RW]
width[RW]

Public Class Methods

new(encoding_id, stream_id, hash = {}) click to toggle source
# File lib/bitmovin/encoding/encodings/sprites/sprite.rb, line 4
def initialize(encoding_id, stream_id, hash = {})
  @errors = []
  init_instance(File.join('/v1/encoding/encodings', encoding_id, 'streams', stream_id, 'sprites'))

  @encoding_id = encoding_id
  @stream_id = stream_id

  hsh = ActiveSupport::HashWithIndifferentAccess.new(underscore_hash(hash))
  @height = hsh[:height]
  @width = hsh[:width]
  @sprite_name = hsh[:sprite_name]
  @vtt_name = hsh[:vtt_name]
  @distance = hsh[:distance]
  @outputs = (hsh[:outputs] || []).map {|output| Bitmovin::Encoding::StreamOutput.new(output)}
end

Public Instance Methods

errors() click to toggle source
# File lib/bitmovin/encoding/encodings/sprites/sprite.rb, line 28
def errors
  @errors
end
invalid?() click to toggle source
# File lib/bitmovin/encoding/encodings/sprites/sprite.rb, line 41
def invalid?
  !valid?
end
save!() click to toggle source
Calls superclass method Bitmovin::Resource#save!
# File lib/bitmovin/encoding/encodings/sprites/sprite.rb, line 22
def save!
  if valid?
    super
  end
end
valid?() click to toggle source
# File lib/bitmovin/encoding/encodings/sprites/sprite.rb, line 32
def valid?
  validate!
  unless @errors.empty?
    puts errors
    return false
  end
  true
end
validate!() click to toggle source
# File lib/bitmovin/encoding/encodings/sprites/sprite.rb, line 45
def validate!
  @errors = []

  if @height == nil || @height < 0
    @errors << 'The height has to be set and must be greater than 0'
  end

  if @width == nil || @width < 0
    @errors << 'The width has to be set and must be greater than 0'
  end

  if @sprite_name == nil || @sprite_name.blank?
    @errors << 'The spriteName has to be set and must not be blank'
  end

  if @vtt_name == nil || @vtt_name.blank?
    @errors << 'The vttName has to be set and must not be blank'
  end

  if @distance < 0
    @errors << 'The distance is not allowed to be less than 0'
  end

  @outputs.each do |output|
    @errors << output.errors unless output.valid?
  end

  @errors.flatten!
end