Class: Puppet::Cleaner::Part
- Inherits:
-
Object
- Object
- Puppet::Cleaner::Part
show all
- Defined in:
- lib/puppet-cleaner/parts.rb
Constant Summary
collapse
- DQSPECIAL =
what makes a double quote string special
{
"\n" => "\\n",
"\r" => "\\r",
"\t" => "\\t"
}
- DQESCAPE =
DQSPECIAL.dup
- SQESCAPE =
{
"'" => "\\'"
}
- DQPATTERN =
/[#{DQESCAPE.keys.map{|key| key.inspect[1..-2]}.join}]/
- SQPATTERN =
/[#{SQESCAPE.keys.map{|key| key.inspect[1..-2]}.join}]/
- SPECIAL_ESCAPE_SEQUENCES =
/[#{DQSPECIAL.keys.map{|key| key.inspect[1..-2]}.join}]/
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(raw) ⇒ Part
Returns a new instance of Part.
33
34
35
|
# File 'lib/puppet-cleaner/parts.rb', line 33
def initialize(raw)
@raw = raw
end
|
Class Method Details
.create(raw) ⇒ Object
24
25
26
27
28
29
30
31
|
# File 'lib/puppet-cleaner/parts.rb', line 24
def self.create(raw)
begin
klass = Puppet::Cleaner.const_get(raw[0].to_s.capitalize.to_sym)
klass.new(raw)
rescue NameError => e
Part.new(raw)
end
end
|
Instance Method Details
#dqescape ⇒ Object
65
66
67
|
# File 'lib/puppet-cleaner/parts.rb', line 65
def dqescape
value.gsub(Part::DQPATTERN) {|match| Part::DQESCAPE[match]}
end
|
#has_special_escape_sequences? ⇒ Boolean
37
38
39
|
# File 'lib/puppet-cleaner/parts.rb', line 37
def has_special_escape_sequences?
value =~ SPECIAL_ESCAPE_SEQUENCES
end
|
#name ⇒ Object
45
46
47
|
# File 'lib/puppet-cleaner/parts.rb', line 45
def name
@raw[0]
end
|
#name=(name) ⇒ Object
49
50
51
|
# File 'lib/puppet-cleaner/parts.rb', line 49
def name=(name)
@raw[0] = name
end
|
#show(context) ⇒ Object
41
42
43
|
# File 'lib/puppet-cleaner/parts.rb', line 41
def show(context)
print to_s
end
|
#sqescape ⇒ Object
69
70
71
72
73
74
|
# File 'lib/puppet-cleaner/parts.rb', line 69
def sqescape
ret = value.gsub(Part::SQPATTERN) {|match| Part::SQESCAPE[match]}
ret =~ /\\+$/
ret += "\\" if $& && $&.size % 2 == 1
ret
end
|
#to_s ⇒ Object
53
54
55
|
# File 'lib/puppet-cleaner/parts.rb', line 53
def to_s
value.to_s
end
|
#value ⇒ Object
57
58
59
|
# File 'lib/puppet-cleaner/parts.rb', line 57
def value
@raw[1][:value]
end
|
#value=(value) ⇒ Object
61
62
63
|
# File 'lib/puppet-cleaner/parts.rb', line 61
def value=(value)
@raw[1][:value] = value
end
|