Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connor Martinelli HW Solutions #8

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 68 additions & 5 deletions username.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,77 @@
# Make sure to run the tests in your /spec folder
# Run `rspec /spec/username_spec.rb` to get started.

$argument_list = []

ARGV.each do|a|
# puts "Argument: #{a}"
$argument_list.push(a)
end

def format_name(first, last)
nil
if (first == "" || last == "")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works great, but Ruby has lots of fun methods. Check out .empty?

nil
else
# (first.gsub(/\s+/, "")[0] + last.gsub(/\s+/, "")).downcase
(first.gsub(/[^A-Za-z]/, "")[0] + last.gsub(/[^A-Za-z]/, "")).downcase
end
end

def format_year(year)
str = year.to_s
str.length == 4 ? str.slice(2,3) : nil
end

def check_privilege(num = 0)
rounded_num = num.floor
if rounded_num == 1
"seller"
elsif rounded_num == 2
"manager"
elsif rounded_num >= 3
"admin"
else
"user"
end
end


def user_type_prefix (num = 0)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice.

if (check_privilege(num) == "user")
""
else
check_privilege(num) + "-"
end
end


def build_username(first, last, year, privilege = 0)
user_type_prefix(privilege) + format_name(first, last) + format_year(year)
end

def format_year
nil

$list_of_usernames = []

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool! Looks good.


def generate_username(first, last, year, privilege = 0)
created_username = build_username(first, last, year, privilege)
if $list_of_usernames.include? created_username
count = 1
while $list_of_usernames.include? created_username
if count > 1
created_username.slice!(-1)
created_username.slice!(-1)
end
created_username = created_username + "_#{count}"
count += 1
end
end
$list_of_usernames.push(created_username)
created_username

end

def build_username
nil
if $argument_list.length == 3
puts generate_username($argument_list[0], $argument_list[1], $argument_list[2])
elsif $argument_list.length == 4
puts generate_username($argument_list[0], $argument_list[1], $argument_list[2], $argument_list[3].to_i)
end
17 changes: 11 additions & 6 deletions warmup.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
# Run `rspec spec/the_warmup_spec.rb` to get started.

def say_hello
"hi"
"hello"
end

def scream(message)
message
message.upcase + "!"
end

def first_char
"z"
def first_char(string)
string[0].downcase
end

def polly_wanna
"crackercrackercracker"
def polly_wanna(word)
word*3
end


def after_you
"no, after you"
end