Class: Woody::Decorators::Video

Inherits:
Base
  • Object
show all
Defined in:
lib/woody/decorators/video.rb

Instance Method Summary collapse

Methods inherited from Base

#method_missing

Constructor Details

#initialize(model, config, creator_model = nil) ⇒ Video

Returns a new instance of Video.



14
15
16
17
18
# File 'lib/woody/decorators/video.rb', line 14

def initialize(model, config, creator_model = nil)
  @config        = config
  @creator_model = creator_model
  super(model)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Woody::Decorators::Base

Instance Method Details

#aspect_ratioObject



20
21
22
23
24
25
# File 'lib/woody/decorators/video.rb', line 20

def aspect_ratio
  @aspect_ratio ||= Helper::AspectRatio.new(
    original_version.height,
    original_version.width
  ).class_name
end

#brandObject



27
28
29
30
31
32
# File 'lib/woody/decorators/video.rb', line 27

def brand
  @brand ||= Woody::Decorators::Brand.new(
    Wes::Data::API::Brand.find(:id, brief.brand_id),
    @config
  )
end

#briefObject



34
35
36
37
38
39
# File 'lib/woody/decorators/video.rb', line 34

def brief
  @brief ||= Woody::Decorators::Brief.new(
    Wes::Data::API::Brief.find(:id, submission.brief_id),
    @config
  )
end

#creatorObject



41
42
43
44
45
# File 'lib/woody/decorators/video.rb', line 41

def creator
  @creator ||= @creator_model ? @creator_model : Wes::Data::API::CreatorUser.find(
    :id, submission.user_id
  )
end

#error?Boolean

Returns:

  • (Boolean)


55
56
57
58
59
60
61
62
63
# File 'lib/woody/decorators/video.rb', line 55

def error?
  @model.attributes.transcoding_states.map do |transcoding_state|
    if transcoding_state['state'] == "error"
      return true
    end
  end

  false
end

#gifObject



65
66
67
68
69
70
71
# File 'lib/woody/decorators/video.rb', line 65

def gif
  return 'https://i.imgur.com/jZCPUYx.gif' if dev?
  return processing_image unless states?('gif')
  video_transcoding_state('gif').path(
    filename_hash, nil, processing_image
  )
end

#original_versionObject



47
48
49
50
51
52
53
# File 'lib/woody/decorators/video.rb', line 47

def original_version
  @original_version ||= Wes::Data::API::Model::VideoVersion.new(
    @model.versions.sort do |a,b|
      DateTime.parse(a['created_at']) <=> DateTime.parse(b['created_at'])
    end.first
  )
end

#processed?Boolean

Returns:

  • (Boolean)


73
74
75
76
77
78
# File 'lib/woody/decorators/video.rb', line 73

def processed?
  return false if error?
  return true if dev?
  return false unless states?('gif') && states?('mp4')
  type_processed?('gif') && type_processed?('mp4')
end

#thumbnailObject



80
81
82
83
84
85
86
87
# File 'lib/woody/decorators/video.rb', line 80

def thumbnail
  return 'https://public.live.vidsy.co/shared/upload-failed.jpg' if error?
  return 'https://i.imgur.com/jZCPUYx.gif' if dev?
  return processing_image unless states?('gif')
  video_transcoding_state('gif').path(
    filename_hash, 'thumbnail', processing_image
  )
end

#urlObject



89
90
91
92
93
# File 'lib/woody/decorators/video.rb', line 89

def url
  return dev_url if dev?
  return '' unless states?('mp4')
  video_transcoding_state('mp4').path(filename_hash)
end