class Spinna::Picker

The picker is responsible for reading the media library, selecting albums from it and updating the history log. Basically, it does the grunt work.

Attributes

config[RW]
history[RW]
library[RW]

Public Class Methods

new(config, history, library) click to toggle source
# File lib/spinna/picker.rb, line 6
def initialize(config, history, library)
  @config = config
  @history = history
  @library = library
end

Public Instance Methods

pick(number_of_picks, pattern = nil) click to toggle source

Picks the requested number of picks from the available albums.

# File lib/spinna/picker.rb, line 13
def pick(number_of_picks, pattern = nil)
  picks = pick_albums(number_of_picks, pattern)
  copy_picks(picks)
  update_history(picks)
  picks
end

Private Instance Methods

choose_random_picks(number_of_picks, albums) click to toggle source

Does the actual picking of random albums.

# File lib/spinna/picker.rb, line 33
def choose_random_picks(number_of_picks, albums)
  return albums if albums.size < number_of_picks
  albums.sample(number_of_picks)
end
copy_picks(picks) click to toggle source

Copies the picks to the current working directory.

# File lib/spinna/picker.rb, line 39
def copy_picks(picks)
  picks.each do |pick|
    puts "Copying #{pick}..."
    FileUtils.cp_r("#{config.source_dir}/#{pick}", Dir.pwd)
  end
end
pick_albums(number_of_picks, pattern = nil) click to toggle source
# File lib/spinna/picker.rb, line 26
def pick_albums(number_of_picks, pattern = nil)
  albums = library.pickable_albums(pattern)
  return albums if number_of_picks >= albums.size
  choose_random_picks(number_of_picks, albums)
end
update_history(picks) click to toggle source

Updates the history.

# File lib/spinna/picker.rb, line 47
def update_history(picks)
  picks.each { |pick| history.append(pick) }
  history.save
end