Class: NgpodScraper::Photo

Inherits:
Valuable
  • Object
show all
Defined in:
lib/ngpod_scraper/photo.rb

Instance Method Summary collapse

Instance Method Details

#exists?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/ngpod_scraper/photo.rb', line 11

def exists?
  Pow(path).exists?
end

#imageObject



15
16
17
# File 'lib/ngpod_scraper/photo.rb', line 15

def image
  @image ||= Magick::ImageList.new(path)
end

#pathObject



19
20
21
22
23
# File 'lib/ngpod_scraper/photo.rb', line 19

def path
  return @path if defined?(@path)
  path_format_in_a_string = %Q{"#{path_format}"}
  @path = Pow(eval(path_format_in_a_string)).to_s
end

#saveObject



25
26
27
28
29
# File 'lib/ngpod_scraper/photo.rb', line 25

def save
  Pow(path).create "w" do |f|
    f.write file.read
  end
end

#save_wallpaperObject



31
32
33
34
# File 'lib/ngpod_scraper/photo.rb', line 31

def save_wallpaper
  Pow(wallpaper_path).parent.create
  wallpaper.write(wallpaper_path)
end

#wallpaperObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/ngpod_scraper/photo.rb', line 36

def wallpaper
  scale = wallpaper_scale
  resized_image = image.resize(scale * image.columns, scale * image.rows)

  background_color = wallpaper_background_color
  background = Magick::Image.new(wallpaper_width, wallpaper_height){
    self.background_color = background_color
  }

  background.composite(resized_image,
    (wallpaper_width - resized_image.columns)/2,
    (wallpaper_height - resized_image.rows)/2,
    Magick::OverCompositeOp)
end

#wallpaper_pathObject



51
52
53
54
55
# File 'lib/ngpod_scraper/photo.rb', line 51

def wallpaper_path
  return @wallpaper_path if defined?(@wallpaper_path)
  wallpaper_path_format_in_a_string = %Q{"#{wallpaper_path_format}"}
  @wallpaper_path = Pow(eval(wallpaper_path_format_in_a_string)).to_s
end

#wallpaper_scaleObject



57
58
59
# File 'lib/ngpod_scraper/photo.rb', line 57

def wallpaper_scale
  [wallpaper_height.to_f/image.rows, wallpaper_width.to_f/image.columns, 1].min
end