forked from sf-wdi-18/username_generator
-
Notifications
You must be signed in to change notification settings - Fork 33
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
conmart
wants to merge
8
commits into
SF-WDI-LABS:master
Choose a base branch
from
conmart:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+79
−11
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e485cff
first two warmups working
conmart 85407a9
warmups all working
conmart 877e642
format_name works
conmart c0c696e
only 1 fail
conmart 862db38
got bonus option 2 but pretty janky
conmart 27535de
peeked at solutions
conmart efd802a
fixed the bonus
conmart 5dfcb05
fixed bonus for real
conmart File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 == "") | ||
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 = [] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?