Module: IoSyncUtils

Included in:
Readline
Defined in:
lib/iosync.rb

Instance Method Summary collapse

Instance Method Details

#ensure_newline(*_opt) ⇒ Object


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

def ensure_newline(*_opt)
  _opt = switch_ensure_newline(*_opt)
  _opt
end

#ensure_newline_array(_arr) ⇒ Object


34
35
36
37
38
39
# File 'lib/iosync.rb', line 34

def ensure_newline_array(_arr)
  if _arr && _arr.length > 0
    _arr[_arr.length-1] = switch_ensure_newline(_arr[_arr.length-1]) 
  end
  _arr
end

#ensure_newline_string(_str) ⇒ Object


27
28
29
30
31
32
# File 'lib/iosync.rb', line 27

def ensure_newline_string(_str)
  if _str && _str.length > 0 && _str.strip[-1..-1] != '\n'
    _str +="\n" 
  end
  _str
end

#switch_ensure_newline(_opt) ⇒ Object


14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/iosync.rb', line 14

def switch_ensure_newline(_opt)
  $max+=1
  exit if $max > 100
  if _opt
    if _opt.kind_of?(String)
      _opt = ensure_newline_string(_opt)
    elsif _opt.kind_of?(Array) 
      _opt = ensure_newline_array(_opt)
    end
  end
  _opt
end