Class: TaggedFile

Inherits:
Object
  • Object
show all
Defined in:
lib/flickrup/filetype/tagged_file.rb

Direct Known Subclasses

TaggedImage, TaggedVideo

Constant Summary collapse

@@subclasses =
{}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ TaggedFile

Returns a new instance of TaggedFile.



21
22
23
# File 'lib/flickrup/filetype/tagged_file.rb', line 21

def initialize(filename)
  @parsed = MiniExiftool.new filename
end

Class Method Details

.create(file) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/flickrup/filetype/tagged_file.rb', line 13

def self.create(file)
  c = @@subclasses[File.extname(file)[1..-1]]

  if c
    c.new(file)
  end
end

.register_reader(exts) ⇒ Object



7
8
9
10
11
# File 'lib/flickrup/filetype/tagged_file.rb', line 7

def self.register_reader(exts)
  exts.map do |ext|
    @@subclasses[ext] = self
  end
end

Instance Method Details

#archive(archive_handlers, to_dir) ⇒ Object



60
61
62
63
64
65
66
# File 'lib/flickrup/filetype/tagged_file.rb', line 60

def archive(archive_handlers, to_dir)
  archive_handlers.archive(ProcessingContext.new(self, {
      :archive_dir => to_dir,
      :date_taken => @parsed.date_time_original || @parsed.modifydate || @parsed.filemodifydate,
      :filename => @filename
  }))
end

#date_createdObject



76
77
78
# File 'lib/flickrup/filetype/tagged_file.rb', line 76

def date_created
  @parsed.date_time_original
end

#doUpload(preupload_handlers, uploader) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/flickrup/filetype/tagged_file.rb', line 25

def doUpload(preupload_handlers, uploader)

    context = preupload_handlers.reduce(ProcessingContext.new(self)) do |ctx, handler|
      if ctx != nil
        handler.preupload(ctx)
      else
        nil
      end
    end

    if context == nil
      false
    else
      pre_upload
      uploader.upload(context)
      post_upload
      true
    end
end

#post_uploadObject



72
73
74
# File 'lib/flickrup/filetype/tagged_file.rb', line 72

def post_upload

end

#pre_uploadObject



68
69
70
# File 'lib/flickrup/filetype/tagged_file.rb', line 68

def pre_upload

end

#tagsObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/flickrup/filetype/tagged_file.rb', line 45

def tags
  keywords = self['keywords']
  TagSet.new(if keywords == nil
               []
             elsif keywords.class == String
               [keywords]
             elsif keywords.class == Integer
               keywords.to_s
             else
               keywords.map do |keyword|
                 keyword.to_s
               end
             end)
end