Class: StringEnhancer::Transformer::Chain

Inherits:
Object
  • Object
show all
Defined in:
lib/string_enhancer/transformer.rb

Instance Method Summary collapse

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_caseObject



44
45
46
47
# File 'lib/string_enhancer/transformer.rb', line 44

def alternating_case
  @transformations << :alternating_case
  self
end

#applyObject



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

#downcaseObject



19
20
21
22
# File 'lib/string_enhancer/transformer.rb', line 19

def downcase
  @transformations << :downcase
  self
end

#remove_consonantsObject



39
40
41
42
# File 'lib/string_enhancer/transformer.rb', line 39

def remove_consonants
  @transformations << :remove_consonants
  self
end

#remove_vowelsObject



34
35
36
37
# File 'lib/string_enhancer/transformer.rb', line 34

def remove_vowels
  @transformations << :remove_vowels
  self
end

#reverseObject



24
25
26
27
# File 'lib/string_enhancer/transformer.rb', line 24

def reverse
  @transformations << :reverse
  self
end

#reverse_wordsObject



49
50
51
52
# File 'lib/string_enhancer/transformer.rb', line 49

def reverse_words
  @transformations << :reverse_words
  self
end

#stripObject



29
30
31
32
# File 'lib/string_enhancer/transformer.rb', line 29

def strip
  @transformations << :strip
  self
end

#titleizeObject



9
10
11
12
# File 'lib/string_enhancer/transformer.rb', line 9

def titleize
  @transformations << :titleize
  self
end

#upcaseObject



14
15
16
17
# File 'lib/string_enhancer/transformer.rb', line 14

def upcase
  @transformations << :upcase
  self
end