Class: MediaArchiver::MediaFile

Inherits:
Object
  • Object
show all
Defined in:
lib/media_archiver/media_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path) ⇒ MediaFile

Returns a new instance of MediaFile.



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/media_archiver/media_file.rb', line 5

def initialize(file_path)
  @path = file_path
  @file_name = File.basename(@path)

  begin
    @file = MiniExiftool.new(file_path)
    @exif_tags = @file.to_hash.each_with_object({}) do |(k, v), acc|
      acc[k.downcase] = v if k
    end
  rescue MiniExiftool::Error
    nil
  end
end

Instance Attribute Details

#exif_tagsObject (readonly)

Returns the value of attribute exif_tags.



3
4
5
# File 'lib/media_archiver/media_file.rb', line 3

def exif_tags
  @exif_tags
end

#file_nameObject (readonly)

Returns the value of attribute file_name.



3
4
5
# File 'lib/media_archiver/media_file.rb', line 3

def file_name
  @file_name
end

#pathObject (readonly)

Returns the value of attribute path.



3
4
5
# File 'lib/media_archiver/media_file.rb', line 3

def path
  @path
end

Instance Method Details

#valid?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/media_archiver/media_file.rb', line 19

def valid?
  @file && @exif_tags
end