Class: Jekyll::GalleryImage

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/jekyll-gallery-generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, base) ⇒ GalleryImage

Returns a new instance of GalleryImage.



16
17
18
19
# File 'lib/jekyll-gallery-generator.rb', line 16

def initialize(name, base)
  @name = name
  @path = File.join(base, name)
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



13
14
15
# File 'lib/jekyll-gallery-generator.rb', line 13

def name
  @name
end

#pathObject

Returns the value of attribute path.



14
15
16
# File 'lib/jekyll-gallery-generator.rb', line 14

def path
  @path
end

Instance Method Details

#<=>(b) ⇒ Object



21
22
23
24
# File 'lib/jekyll-gallery-generator.rb', line 21

def <=>(b)
  cmp = @date_time <=> b.date_time
  return cmp == 0 ? @name <=> b.name : cmp
end

#date_timeObject



26
27
28
29
30
31
32
33
34
# File 'lib/jekyll-gallery-generator.rb', line 26

def date_time
  return @date_time if defined? @date_time
  begin
    @date_time = self.exif.date_time.to_i
  rescue Exception => e
    @date_time = 0
  end
  return @date_time
end

#exifObject



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/jekyll-gallery-generator.rb', line 36

def exif
  return @exif if defined? @exif
  @exif = nil
  begin
    @exif = EXIFR::JPEG.new(@path)
  rescue EXIFR::MalformedJPEG
    puts "No EXIF data in #{@path}"
  rescue Exception => e
    puts "Error reading EXIF data for #{@path}: #{e}"
  end
  return @exif
end

#to_liquidObject



53
54
55
56
57
58
59
60
61
# File 'lib/jekyll-gallery-generator.rb', line 53

def to_liquid
  # Liquid hates symbol keys. Gotta stringify them
  return {
    'name' => @name,
    'src' => @name,
    'date_time' => @date_time,
    'exif' => @exif && @exif.to_hash.collect{|k,v| [k.to_s, v]}.to_h,
  }
end

#to_sObject



49
50
51
# File 'lib/jekyll-gallery-generator.rb', line 49

def to_s
  return @name
end