Sha256: 7d53ec2a4629301c3050f4d760dac8932a2d94c77eb8904fc787773d3776ba75

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

#!/usr/bin/env ruby

# require '../lib/codebadges/badges.rb'     # for cmd line testing purposes
require 'codebadges'                       # for production

def get_users_array_from_file(file)
  users_array = []

  File.open(file, 'r') do |f|
    f.each_line.map do |line|
      next if line.chomp.empty?
      users_array.push(line.gsub("\n", ''))
    end
  end

  users_array
end

type = ['txt']
fail ArgumentError, "Usage:  badges [username/file]\n" if ARGV.count == 0
if type.include? ARGV[0].split('.').last
  users_array = get_users_array_from_file(ARGV[0])

  badges_found_from_file = CodeBadges::Academy.get_cadets(users_array)

  badges_found_from_file.each_with_index do |(k, v), _|
    puts "#{k} has collected #{v.size} badges."
    v.each do |title, date|
      puts "Earned '#{title}' on #{date}."
    end
    puts "\n"
  end
else
  user_name = ARGV[0]

  badges_found = CodeBadges::CodecademyBadges.get_badges(user_name)

  puts "#{user_name} has collected #{badges_found.size} badges."

  badges_found.each do |title, date|
    puts "Earned '#{title}' on #{date}."
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
codebadges-1.0.0 bin/codebadges