You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/design.md
+32Lines changed: 32 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,6 +18,13 @@ From the original requirements specification,
18
18
> 1. The project should include an automated test suite.
19
19
> 2. The project should include a README file with instructions for running the web service and its tests. You should also use the README to provide context on choices made during development.
20
20
> 3. The project should be packaged as a zip file or submitted via a hosted git platform (Github, Gitlab, etc).
21
+
>
22
+
> **Additional Requirements**:
23
+
>
24
+
> 1. Calculate a cost for each slug, where consonants cost $1, vowels $2 and any repeated character costs $1 extra.
25
+
> a. ex: goly -> $5, oely -> $6, gole -> $6
26
+
> 2. Add a suggestion service that given a valid hostname (characters only) suggests a slug that has minimal cost.
27
+
> a. ex: goldbelly -> gldb ($4), google -> golg ($6), hi -> hihh ($7)
21
28
22
29
## Product Design
23
30
@@ -174,6 +181,31 @@ This project includes a [root README file](../README.md) which references this d
174
181
175
182
This project is hosted using [GitHub](https://github.com/) at [https://github.com/truggeri/rails-url-shortener](https://github.com/truggeri/rails-url-shortener).
176
183
184
+
## Additional Requirements
185
+
186
+
A later pairing session brought about the following additions.
187
+
188
+
### Cost Calculation
189
+
190
+
The cost calculation is done as a [before-validation action on the `Short` model](https://github.com/truggeri/rails-url-shortener/blob/6d94c5c421e59b95427749c15f62b4de91d0f8b8/app/models/short.rb#L34).
191
+
It iterates over each character and tallies a cost per character.
192
+
A slight modification was made to allow for digits and `-_` characters at a cost of $3 each. Reoccurrences are
193
+
handled by a hash for quick access. This cost is then saved to the model to avoid recalculation.
194
+
195
+
### Suggestion Service
196
+
197
+
There is a [suggestion service](https://github.com/truggeri/rails-url-shortener/blob/main/app/lib/suggestion.rb)
198
+
that takes in a hostname (such as `google`) and outputs a suggestion at minimal cost.
199
+
This works by breaking the hostname into possible characters (consonants and vowels), then iterating in order of
200
+
201
+
* Unused consonants ($1 each)
202
+
* Unused vowels ($2 each)
203
+
* Used consonants ($2 each)
204
+
* Used vowels ($3 each)
205
+
206
+
A random selection is done for each used character to provide unique suggestions. A randomization _could_ be done
207
+
on all characters after the generation too.
208
+
177
209
## Future Improvements
178
210
179
211
To see areas for improvement, [read our documentation](./future_improvements.md).
0 commit comments