Class: Bulldog::Processor::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/bulldog/processor/base.rb

Direct Known Subclasses

Ffmpeg, ImageMagick, OneShot

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attachment, input_file) ⇒ Base

Returns a new instance of Base.



4
5
6
7
# File 'lib/bulldog/processor/base.rb', line 4

def initialize(attachment, input_file)
  @attachment = attachment
  @input_file = input_file
end

Instance Attribute Details

#attachmentObject (readonly)

The attachment object being processed.



12
13
14
# File 'lib/bulldog/processor/base.rb', line 12

def attachment
  @attachment
end

#input_fileObject (readonly)

The name of the original file.



36
37
38
# File 'lib/bulldog/processor/base.rb', line 36

def input_file
  @input_file
end

#styleObject (readonly)

The current style being processed.



84
85
86
# File 'lib/bulldog/processor/base.rb', line 84

def style
  @style
end

#stylesObject (readonly)

The styles to run this processor for.



17
18
19
# File 'lib/bulldog/processor/base.rb', line 17

def styles
  @styles
end

Instance Method Details

#nameObject

The name of the attachment being processed.



29
30
31
# File 'lib/bulldog/processor/base.rb', line 29

def name
  attachment.name
end

#output_file(style_name) ⇒ Object

The name of the output file for the given style.



41
42
43
44
45
46
47
# File 'lib/bulldog/processor/base.rb', line 41

def output_file(style_name)
  overrides = {}
  if (format = styles[style_name][:format])
    overrides[:extension] = format
  end
  attachment.interpolate_path(style_name, overrides)
end

#process(styles, options = {}, &block) ⇒ Object

Run the given block in the context of this processor, once for each style.

#style will be set to the current style each time the block is called.

Return true if any styles were processed, false otherwise. Subclasses can use this to determine if any processing commands need to be run.



67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/bulldog/processor/base.rb', line 67

def process(styles, options={}, &block)
  @styles = styles
  return false if styles.empty?
  styles.each do |style|
    @style = style
    begin
      process_style(&block)
    ensure
      @style = nil
    end
  end
  true
end

#recordObject

The record being processed.



22
23
24
# File 'lib/bulldog/processor/base.rb', line 22

def record
  attachment.record
end

#valueObject

Return the value of the attachment.



52
53
54
# File 'lib/bulldog/processor/base.rb', line 52

def value
  record.send(name).value
end