Sha256: 31688d6b8e283a8ea8f22f8da3107b06b58d4a3eb7dae07fcc082b931680b5f1

Contents?: true

Size: 1.82 KB

Versions: 4

Compression:

Stored size: 1.82 KB

Contents

module Movier

  # ask a user for a directory path, until we find one
  #
  # * *Args*    :
  #   - +message+ -> question to show to the user
  # * *Returns* :
  #   - path to the provided directory
  #
  def self.ask_for_directory(message = nil)
    message ||= "Please, provide a directory path to use. "
    dir = nil
    until dir && File.directory?(dir)
      warn_with "Found no such directory!" if dir
      dir = ask(message) { |x| x.default = ENV['HOME'] }
    end
    dir
  end

  # colorize output based on a movie's rating
  #
  # * *Args*    :
  #   - +status+ -> status for this message
  #   - +message+ -> actual message
  #   - +rating+ -> rating for this movie
  #
  def self.say_rated(status, message, rating, do_break = false)
    rating = rating.to_f
    scheme = :below6 if rating < 6
    scheme = :above6 if rating >= 6
    scheme = :above8 if rating >= 8
    say_with_status status, message, scheme, do_break
  end

  # titleize a string
  #
  # * *Args*    :
  #   - +string+ -> string that will be titleized
  # * *Returns* :
  #   - titleized string
  #
  def self.titleize(string)
    string.gsub(/\w+/) { |word| word.capitalize }
  end

  # find the imdb.txt file for a given movie path
  # this file is created by Movier, once the movie has been parsed
  #
  # * *Args*    :
  #   - +movie_path+ -> path to the movie being checked
  # * *Returns* :
  #   - path to the imdb.txt file for the given movie path
  #
  def self.imdb_file_for(movie_path)
    File.join(File.dirname(movie_path), "imdb.txt")
  end

  # check whether the movie with given path has already been organized
  #
  # * *Args*    :
  #   - +movie_path+ -> path to the movie being checked
  # * *Returns* :
  #   - true, if the movie has been organized. false, otherwise
  #
  def self.organized?(movie_path)
    File.exists?(imdb_file_for(movie_path))
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
movier-0.1.2 lib/movier/helpers.rb
movier-0.1.1 lib/movier/helpers.rb
movier-0.1.0 lib/movier/helpers.rb
movier-0.0.9 lib/movier/helpers.rb