Module: Numeronym
- Defined in:
- lib/numeronym.rb,
lib/numeronym/version.rb
Constant Summary collapse
- VERSION =
"0.1.0"
Class Method Summary collapse
-
.phrase(input) ⇒ Object
Phrase style: “Andreessen Horowitz” => “A16z”.
-
.robot(input) ⇒ Object
Robot style: “robot eyes” => “R4-E3”.
-
.word(input) ⇒ Object
Word style: “internationalization” => “i18n”.
Class Method Details
.phrase(input) ⇒ Object
Phrase style: “Andreessen Horowitz” => “A16z”.
9 10 11 12 13 14 15 |
# File 'lib/numeronym.rb', line 9 def phrase(input) str = normalize(input) return str if str.length < 3 middle_count = str[1...-1].scan(/\S/).size "#{str[0]}#{middle_count}#{str[-1]}" end |
.robot(input) ⇒ Object
Robot style: “robot eyes” => “R4-E3”.
24 25 26 27 |
# File 'lib/numeronym.rb', line 24 def robot(input) str = normalize(input) str.split.map { |w| "#{w[0]}#{w.length - 1}" }.join("-").upcase end |
.word(input) ⇒ Object
Word style: “internationalization” => “i18n”.
18 19 20 21 |
# File 'lib/numeronym.rb', line 18 def word(input) str = normalize(input) str.length > 3 ? "#{str[0]}#{str.length - 2}#{str[-1]}" : str end |