Class: Roart::Attachment

Inherits:
Struct
  • Object
show all
Defined in:
lib/roart/attachment.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#fileObject

Returns the value of attribute file

Returns:

  • (Object)

    the current value of file



13
14
15
# File 'lib/roart/attachment.rb', line 13

def file
  @file
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



13
14
15
# File 'lib/roart/attachment.rb', line 13

def name
  @name
end

Class Method Details

.detect(*args) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/roart/attachment.rb', line 23

def self.detect(*args)
  AttachmentCollection.new Array(args.compact).flatten.map { |file|
    if file.is_a?(File)
      Attachment.new(File.basename(file.path), file)
    elsif file.is_a?(String)
      Attachment.new(File.basename(file), File.open(file, 'rb'))
    elsif file.respond_to?(:open, :original_filename)
      Attachment.new(file.original_filename, file.open)
    end
  }.compact
end

Instance Method Details

#pathObject



15
16
17
# File 'lib/roart/attachment.rb', line 15

def path
  name
end

#readObject



19
20
21
# File 'lib/roart/attachment.rb', line 19

def read
  file.read
end