Class: Pageflow::ZencoderAttachment

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of ZencoderAttachment.



15
16
17
18
19
20
21
# File 'app/models/pageflow/zencoder_attachment.rb', line 15

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

  @styles = {}
end

Instance Attribute Details

#file_name_patternObject (readonly)

Returns the value of attribute file_name_pattern.



13
14
15
# File 'app/models/pageflow/zencoder_attachment.rb', line 13

def file_name_pattern
  @file_name_pattern
end

#instanceObject (readonly)

Returns the value of attribute instance.



13
14
15
# File 'app/models/pageflow/zencoder_attachment.rb', line 13

def instance
  @instance
end

#optionsObject (readonly)

Returns the value of attribute options.



13
14
15
# File 'app/models/pageflow/zencoder_attachment.rb', line 13

def options
  @options
end

#stylesObject (readonly)

Returns the value of attribute styles.



13
14
15
# File 'app/models/pageflow/zencoder_attachment.rb', line 13

def styles
  @styles
end

Instance Method Details

#base_name_patternObject



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

def base_name_pattern
  File.basename(file_name_pattern)
end

#dir_nameObject



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

def dir_name
  File.dirname(path)
end

#formatObject



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

def format
  options[:format]
end

#original_filenameObject



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

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

#pathObject



39
40
41
# File 'app/models/pageflow/zencoder_attachment.rb', line 39

def path
  Paperclip::Interpolations.interpolate(options[:path], self, 'default')
end

#url(url_options = {}) ⇒ Object



43
44
45
46
# File 'app/models/pageflow/zencoder_attachment.rb', line 43

def url(url_options = {})
  ensure_default_protocol(interpolate(url_pattern(url_options)),
                          url_options)
end

#url_relative_to(attachment) ⇒ Object



48
49
50
51
52
53
54
55
56
# File 'app/models/pageflow/zencoder_attachment.rb', line 48

def url_relative_to(attachment)
  dir_path = File.dirname(URI.parse(attachment.url).path)

  unless URI.parse(url).path.start_with?(dir_path)
    raise("Could not generate relative url for #{url} based on #{attachment.url}.")
  end

  url.split("#{dir_path}/", 2).last
end