Class: String

Inherits:
Object show all
Defined in:
lib/platform_helpers/string.rb

Instance Method Summary collapse

Instance Method Details

#eachObject



8
9
10
# File 'lib/platform_helpers/string.rb', line 8

def each
  self.strip.split(' ').each { |i| yield i }
end

#each_lineObject



11
12
13
# File 'lib/platform_helpers/string.rb', line 11

def each_line
  self.strip.split(/\n/).each { |i| yield i }
end

#grep(i) ⇒ Object

1.8.x to 1.9.x compatibility



15
16
17
# File 'lib/platform_helpers/string.rb', line 15

def grep(i) # 1.8.x to 1.9.x compatibility
  self.split(/\n/).grep(i)
end

#naObject



55
56
57
58
59
60
61
# File 'lib/platform_helpers/string.rb', line 55

def na
  if self.empty?
    return 'NA'
  else
    return self
  end
end

#shift(params = {}) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/platform_helpers/string.rb', line 18

def shift(params={})
  if params.has_key?(:del)
    tmp = self.split(params[:del])
    tmp.delete_at(tmp.length-1)
    return tmp.join(params[:del])
  else
    return self[0..self.length-2]
  end
end

#to_bool(na = false) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/platform_helpers/string.rb', line 39

def to_bool(na=false)
  if self =~ /^true$/i
    return true
  elsif self =~ /^false$/i
    if na
      return 'NA'
    else
      return false
    end
  elsif self.strip == ''
    return false
  else
    return false
  end
end

#to_display(params = {}) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'lib/platform_helpers/string.rb', line 28

def to_display(params={})
  if params.has_key?(:na)
    return self.na if params[:na].to_bool
  end
  if self.to_bool
    return 'Yes'
  else
    return 'No'
  end
end