Class: StringEnhancer::Transformer::Chain
- Inherits:
-
Object
- Object
- StringEnhancer::Transformer::Chain
- Defined in:
- lib/string_enhancer/transformer.rb
Instance Method Summary collapse
- #alternating_case ⇒ Object
- #apply ⇒ Object
- #custom(&block) ⇒ Object
- #downcase ⇒ Object
-
#initialize(str) ⇒ Chain
constructor
A new instance of Chain.
- #remove_consonants ⇒ Object
- #remove_vowels ⇒ Object
- #reverse ⇒ Object
- #reverse_words ⇒ Object
- #strip ⇒ Object
- #titleize ⇒ Object
- #upcase ⇒ Object
Constructor Details
#initialize(str) ⇒ Chain
Returns a new instance of Chain.
4 5 6 7 |
# File 'lib/string_enhancer/transformer.rb', line 4 def initialize(str) @str = str @transformations = [] end |
Instance Method Details
#alternating_case ⇒ Object
44 45 46 47 |
# File 'lib/string_enhancer/transformer.rb', line 44 def alternating_case @transformations << :alternating_case self end |
#apply ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/string_enhancer/transformer.rb', line 59 def apply result = @str.dup @transformations.each do |transformation| if transformation.is_a?(Proc) result = transformation.call(result) else result = StringEnhancer.transform(result, transformation) end end result end |
#custom(&block) ⇒ Object
54 55 56 57 |
# File 'lib/string_enhancer/transformer.rb', line 54 def custom(&block) @transformations << block self end |
#downcase ⇒ Object
19 20 21 22 |
# File 'lib/string_enhancer/transformer.rb', line 19 def downcase @transformations << :downcase self end |
#remove_consonants ⇒ Object
39 40 41 42 |
# File 'lib/string_enhancer/transformer.rb', line 39 def remove_consonants @transformations << :remove_consonants self end |
#remove_vowels ⇒ Object
34 35 36 37 |
# File 'lib/string_enhancer/transformer.rb', line 34 def remove_vowels @transformations << :remove_vowels self end |
#reverse ⇒ Object
24 25 26 27 |
# File 'lib/string_enhancer/transformer.rb', line 24 def reverse @transformations << :reverse self end |
#reverse_words ⇒ Object
49 50 51 52 |
# File 'lib/string_enhancer/transformer.rb', line 49 def reverse_words @transformations << :reverse_words self end |
#strip ⇒ Object
29 30 31 32 |
# File 'lib/string_enhancer/transformer.rb', line 29 def strip @transformations << :strip self end |
#titleize ⇒ Object
9 10 11 12 |
# File 'lib/string_enhancer/transformer.rb', line 9 def titleize @transformations << :titleize self end |
#upcase ⇒ Object
14 15 16 17 |
# File 'lib/string_enhancer/transformer.rb', line 14 def upcase @transformations << :upcase self end |