Skip to content

Commit 2ee45d8

Browse files
committed
Merge pull request #97 from monkbroc/acronym
Added acronym problem
2 parents 9377041 + d685f59 commit 2ee45d8

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

acronym/acronym_test.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
require 'minitest/autorun'
2+
require_relative 'acronym'
3+
4+
class AcronymTest < Minitest::Test
5+
def test_png
6+
assert_equal 'PNG', Acronym.abbreviate('Portable Network Graphics')
7+
end
8+
9+
def test_ruby_on_rails
10+
skip
11+
assert_equal 'ROR', Acronym.abbreviate('Ruby on Rails')
12+
end
13+
14+
def test_html
15+
skip
16+
assert_equal 'HTML', Acronym.abbreviate('HyperText Markup Language')
17+
end
18+
19+
def test_fifo
20+
skip
21+
assert_equal 'FIFO', Acronym.abbreviate('First In, First Out')
22+
end
23+
24+
def test_php
25+
skip
26+
assert_equal 'PHP', Acronym.abbreviate('PHP: Hypertext Preprocessor')
27+
end
28+
29+
def test_cmos
30+
skip
31+
assert_equal 'CMOS', Acronym.abbreviate('Complementary metal-oxide semiconductor')
32+
end
33+
end

acronym/example.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Acronym
2+
def self.abbreviate(phrase)
3+
[].tap do |letters|
4+
each_word(phrase) do |word|
5+
letters << word[0].upcase
6+
end
7+
end.join
8+
end
9+
10+
def self.each_word(phrase)
11+
phrase.scan(/[A-Z]+[a-z]*|[a-z]+/) do |word|
12+
yield word
13+
end
14+
end
15+
end

config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"gigasecond",
99
"rna-transcription",
1010
"raindrops",
11+
"acronym",
1112
"difference-of-squares",
1213
"roman-numerals",
1314
"robot-name",

0 commit comments

Comments
 (0)