Class: Linebook::Os::Posix::Variable

Inherits:
Object
  • Object
show all
Defined in:
lib/linebook/os/posix/variable.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(varname, default = nil) ⇒ Variable

Returns a new instance of Variable.



8
9
10
11
# File 'lib/linebook/os/posix/variable.rb', line 8

def initialize(varname, default=nil)
  @varname = varname.to_s
  @default = default
end

Instance Attribute Details

#defaultObject

Returns the value of attribute default.



6
7
8
# File 'lib/linebook/os/posix/variable.rb', line 6

def default
  @default
end

#varnameObject

Returns the value of attribute varname.



5
6
7
# File 'lib/linebook/os/posix/variable.rb', line 5

def varname
  @varname
end

Instance Method Details

#<(another) ⇒ Object



73
74
75
# File 'lib/linebook/os/posix/variable.rb', line 73

def <(another)
  "[ #{self} < #{another} ]"
end

#==(another) ⇒ Object



61
62
63
# File 'lib/linebook/os/posix/variable.rb', line 61

def ==(another)
  "[ #{self} = #{another} ]"
end

#>(another) ⇒ Object

def !=(another)

"[ #{self} != #{another} ]"

end



69
70
71
# File 'lib/linebook/os/posix/variable.rb', line 69

def >(another)
  "[ #{self} > #{another} ]"
end

#eq(another) ⇒ Object



45
46
47
# File 'lib/linebook/os/posix/variable.rb', line 45

def eq(another)
  "[ #{self} -eq #{another} ]"
end

#gsub(pattern, replacement) ⇒ Object



33
34
35
# File 'lib/linebook/os/posix/variable.rb', line 33

def gsub(pattern, replacement)
  "${#{varname}//#{pattern}/#{replacement}}"
end

#gt(another) ⇒ Object



53
54
55
# File 'lib/linebook/os/posix/variable.rb', line 53

def gt(another)
  "[ #{self} -gt #{another} ]"
end

#lengthObject



37
38
39
# File 'lib/linebook/os/posix/variable.rb', line 37

def length
  "${##{varname}}"
end

#llstrip(pattern) ⇒ Object



17
18
19
# File 'lib/linebook/os/posix/variable.rb', line 17

def llstrip(pattern)
  "${#{varname}###{pattern}}"
end

#lstrip(pattern) ⇒ Object



13
14
15
# File 'lib/linebook/os/posix/variable.rb', line 13

def lstrip(pattern)
  "${#{varname}##{pattern}}"
end

#lt(another) ⇒ Object



57
58
59
# File 'lib/linebook/os/posix/variable.rb', line 57

def lt(another)
  "[ #{self} -lt #{another} ]"
end

#ne(another) ⇒ Object



49
50
51
# File 'lib/linebook/os/posix/variable.rb', line 49

def ne(another)
  "[ #{self} -ne #{another} ]"
end

#not_null?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/linebook/os/posix/variable.rb', line 81

def not_null?
  "[ -n #{self} ]"
end

#null?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/linebook/os/posix/variable.rb', line 77

def null?
  "[ -z #{self} ]"
end

#rrstrip(pattern) ⇒ Object



25
26
27
# File 'lib/linebook/os/posix/variable.rb', line 25

def rrstrip(pattern)
  "${#{varname}%%#{pattern}}"
end

#rstrip(pattern) ⇒ Object



21
22
23
# File 'lib/linebook/os/posix/variable.rb', line 21

def rstrip(pattern)
  "${#{varname}%#{pattern}}"
end

#sub(pattern, replacement) ⇒ Object



29
30
31
# File 'lib/linebook/os/posix/variable.rb', line 29

def sub(pattern, replacement)
  "${#{varname}/#{pattern}/#{replacement}}"
end

#substring(offset, length = nil) ⇒ Object



41
42
43
# File 'lib/linebook/os/posix/variable.rb', line 41

def substring(offset, length=nil)
  length ? "${#{varname}:#{offset}:#{length}}": "${#{varname}:#{offset}}"
end

#to_sObject



85
86
87
# File 'lib/linebook/os/posix/variable.rb', line 85

def to_s
  default.nil? ? "$#{varname}" : "${#{varname}:-#{default}}"
end