Method: SplitWhere::String#split_where

Defined in:
lib/split-where.rb

#split_where(args) ⇒ Object

Note:

exemple: “‘xx’,‘yy,’,l{},‘dg,’g”

Note:

exemple: “a,b,c” 0123456789012345678901234

The new split_where make split of strings using conditions to determine where he can cut or not the string

Parameters:

  • :value (Hash{:value=>String, :outside=>String})

    for split, :outside is a condition to split



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/split-where.rb', line 11

def split_where(args)
  list = []
  enable = true
  s = ""
  count = 0
  while(self[count])
    c = self[count]
    if args[:outside] == c 
      enable = enable ? false : true
    end
    
    if c == args[:value] && enable == true
      list << s
      s=""
    else
      s += c
    end
    count += 1
  end
  list << s if s
  list
end