Class: Tagomatic::TagNormalizer
- Inherits:
-
Object
- Object
- Tagomatic::TagNormalizer
- Defined in:
- lib/tagomatic/tag_normalizer.rb
Constant Summary collapse
- NORMALIZER_SPLIT_REGEX =
/[ _-]+/
- NORMALIZER_LEFT_LITERALS =
Regexp.escape('-([.')
- NORMALIZER_RIGHT_LITERALS =
Regexp.escape('-)].')
- NORMALIZER_STRIP_LEFT =
/^[#{NORMALIZER_LEFT_LITERALS}]+\s*/
- NORMALIZER_STRIP_RIGHT =
/\s*[#{NORMALIZER_RIGHT_LITERALS}]+$/
Instance Method Summary collapse
- #capitalize_words ⇒ Object
- #drop_empty_words ⇒ Object
- #get_resulting_value ⇒ Object
- #process(tags_hash) ⇒ Object
- #split_by_spaces_and_underscores(value) ⇒ Object
- #strip_dashes_and_brackets ⇒ Object
Instance Method Details
#capitalize_words ⇒ Object
32 33 34 |
# File 'lib/tagomatic/tag_normalizer.rb', line 32 def capitalize_words @parts.map! { |part| part.capitalize } end |
#drop_empty_words ⇒ Object
28 29 30 |
# File 'lib/tagomatic/tag_normalizer.rb', line 28 def drop_empty_words @parts = @parts.select { |part| not part.empty? } end |
#get_resulting_value ⇒ Object
36 37 38 |
# File 'lib/tagomatic/tag_normalizer.rb', line 36 def get_resulting_value @parts.join(' ') end |
#process(tags_hash) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/tagomatic/tag_normalizer.rb', line 5 def process() normalized = Hash.new .each do |tag, value| next unless value split_by_spaces_and_underscores value strip_dashes_and_brackets drop_empty_words capitalize_words normalized[tag] = get_resulting_value end normalized end |
#split_by_spaces_and_underscores(value) ⇒ Object
20 21 22 |
# File 'lib/tagomatic/tag_normalizer.rb', line 20 def split_by_spaces_and_underscores(value) @parts = value.split(NORMALIZER_SPLIT_REGEX) end |
#strip_dashes_and_brackets ⇒ Object
24 25 26 |
# File 'lib/tagomatic/tag_normalizer.rb', line 24 def strip_dashes_and_brackets @parts.map! { |part| part.sub(NORMALIZER_STRIP_LEFT, '').sub(NORMALIZER_STRIP_RIGHT, '') } end |