Skip to content

Commit

Permalink
add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
James McKinney committed Feb 27, 2015
1 parent 12ad046 commit 60ae773
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -27,7 +27,7 @@ model.downcase('HP AND IBM ARE TECHNOLOGY CORPORATIONS.')
# => "HP and IBM are technology corporations."
```

![](http://i.giphy.com/ol57TlMlftsQg.gif)
![This gem is magic.](http://i.giphy.com/ol57TlMlftsQg.gif)

IndoorVoice is based on the assumption that most acronyms contain non-word character sequences. For example, no English word has the character sequence `bm` in a word-final position, therefore `IBM` must be an acronym.

Expand Down
4 changes: 4 additions & 0 deletions lib/indoor_voice.rb
Expand Up @@ -43,6 +43,7 @@ def setup
end
end

# Determine the possible two-character sequences. Should be O(n) of all characters in all words.
@words.each do |word|
chars = UnicodeUtils.upcase(word, @language_id).chars
@characters.merge(chars)
Expand All @@ -55,17 +56,20 @@ def setup
end
end

# Determine whether the language contains any characters requiring escaping.
escape = @characters.intersect?(SPECIAL_CHARACTERS)

patterns = {}
types.each do |type|
patterns[type] = []
end

# Build the regular expressions for non-word character sequences.
data.each do |type,hash|
hash.each do |character,set|
difference = @characters - set
unless difference.empty?
# The first condition is just to make the patterns more human-readable.
patterns[type] << if difference.one?
if escape
"#{Regexp.escape(character)}#{Regexp.escape(difference.to_a.first)}"
Expand Down

0 comments on commit 60ae773

Please sign in to comment.