Class: Pageflow::ZencoderAttachment

Inherits:
Object
  • Object
show all
Defined in:
app/models/pageflow/zencoder_attachment.rb

Constant Summary collapse

PATH =
"/:zencoder_asset_version/:host/:class/:id_partition/:filename"
URL =
":zencoder_protocol://:zencoder_host_alias#{PATH}"
HLS_URL =
":zencoder_protocol://:zencoder_hls_host_alias#{PATH}"
HLS_ORIGIN_URL =
":zencoder_protocol://:zencoder_hls_origin_host_alias#{PATH}"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(instance, file_name_pattern, options = {}) ⇒ ZencoderAttachment

Returns a new instance of ZencoderAttachment.



10
11
12
13
14
15
16
# File 'app/models/pageflow/zencoder_attachment.rb', line 10

def initialize(instance, file_name_pattern, options = {})
  @instance = instance
  @file_name_pattern = file_name_pattern
  @options = options

  @styles = {}
end

Instance Attribute Details

#file_name_patternObject (readonly)

Returns the value of attribute file_name_pattern.



8
9
10
# File 'app/models/pageflow/zencoder_attachment.rb', line 8

def file_name_pattern
  @file_name_pattern
end

#instanceObject (readonly)

Returns the value of attribute instance.



8
9
10
# File 'app/models/pageflow/zencoder_attachment.rb', line 8

def instance
  @instance
end

#optionsObject (readonly)

Returns the value of attribute options.



8
9
10
# File 'app/models/pageflow/zencoder_attachment.rb', line 8

def options
  @options
end

#stylesObject (readonly)

Returns the value of attribute styles.



8
9
10
# File 'app/models/pageflow/zencoder_attachment.rb', line 8

def styles
  @styles
end

Instance Method Details

#base_name_patternObject



26
27
28
# File 'app/models/pageflow/zencoder_attachment.rb', line 26

def base_name_pattern
  File.basename(file_name_pattern)
end

#dir_nameObject



22
23
24
# File 'app/models/pageflow/zencoder_attachment.rb', line 22

def dir_name
  File.dirname(path)
end

#formatObject



18
19
20
# File 'app/models/pageflow/zencoder_attachment.rb', line 18

def format
  options[:format]
end

#original_filenameObject



30
31
32
# File 'app/models/pageflow/zencoder_attachment.rb', line 30

def original_filename
  [file_name_pattern.gsub('{{number}}', '0'), options[:format]].compact * '.'
end

#pathObject



34
35
36
# File 'app/models/pageflow/zencoder_attachment.rb', line 34

def path
  Paperclip::Interpolations.interpolate(PATH, self, 'default')
end

#url(url_options = {}) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/models/pageflow/zencoder_attachment.rb', line 38

def url(url_options = {})
  base_url =
    case (url_options[:host] || options[:host])
    when :hls
      HLS_URL
    when :hls_origin
      HLS_ORIGIN_URL
    else
      URL
    end

  Paperclip::Interpolations.interpolate(base_url + suffix(url_options), self, 'default')
end