Class: String

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

Instance Method Summary collapse

Instance Method Details

#each_character_trippleObject



29
30
31
32
33
34
35
36
# File 'lib/shaken.rb', line 29

def each_character_tripple
  index = 0
  character_array = self.scan(/./)
  while index < (character_array.size)
    yield character_array[index-1], character_array[index], character_array[index+1]
    index += 1
  end
end

#shakenObject

not schtirred



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/shaken.rb', line 3

def shaken # not schtirred
  string_to_return = ''
  self.each_character_tripple do |char1, char2, char3|
    string_to_return << char2
    
    case char2
    when "s"
      string_to_return << 'h' unless char3 == 'h' || char3 == 's'
    when "S"
      if char1 =~ /[A-Z]/ && char3 =~ /[A-Z]/
        string_to_return << 'H'
      elsif char1 =~ // && char3 =~ /[A-Z]/
        string_to_return << 'H' 
      elsif char1 =~ /[A-Z]/ && char3 =~ //
        string_to_return << 'H' 
      else
        string_to_return << 'h'
      end
    else
      # Nada
    end
  end
  
  string_to_return
end