Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/damagecontrol/diff_parser.rb,
lib/damagecontrol/diff_htmlizer.rb

Overview

Extra methods added to String to ease diff manipulation

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#added_rangeObject

Returns the value of attribute added_range.



97
98
99
# File 'lib/damagecontrol/diff_parser.rb', line 97

def added_range
  @added_range
end

#removed_rangeObject

Returns the value of attribute removed_range.



96
97
98
# File 'lib/damagecontrol/diff_parser.rb', line 96

def removed_range
  @removed_range
end

Instance Method Details

#addedObject



111
112
113
# File 'lib/damagecontrol/diff_parser.rb', line 111

def added
  added_range ? self[added_range] : nil
end

#added?Boolean

Returns:

  • (Boolean)


107
108
109
# File 'lib/damagecontrol/diff_parser.rb', line 107

def added?
  (self =~ /\+/) == 0
end

#common_prefix_length(o) ⇒ Object



127
128
129
130
131
132
133
134
# File 'lib/damagecontrol/diff_parser.rb', line 127

def common_prefix_length(o)
  length = 0
  each_byte do |char|
    break unless o[length] == char
    length = length + 1
  end
  length
end

#contentObject



123
124
125
# File 'lib/damagecontrol/diff_parser.rb', line 123

def content
  "\n" == self ? "\n" : self[1..-1]
end

#html_encodedObject



72
73
74
75
76
77
78
79
80
81
# File 'lib/damagecontrol/diff_htmlizer.rb', line 72

def html_encoded
  self.gsub(/./) do
    case $&
      when "&" then "&"
      when "<" then "&lt;"
      when ">" then "&gt;"
      else $&
    end
  end
end

#prefixObject



115
116
117
# File 'lib/damagecontrol/diff_parser.rb', line 115

def prefix
  self[0..range.first-1]
end

#removedObject



103
104
105
# File 'lib/damagecontrol/diff_parser.rb', line 103

def removed
  removed_range ? self[removed_range] : nil
end

#removed?Boolean

Returns:

  • (Boolean)


99
100
101
# File 'lib/damagecontrol/diff_parser.rb', line 99

def removed?
  (self =~ /\-/) == 0
end

#suffixObject



119
120
121
# File 'lib/damagecontrol/diff_parser.rb', line 119

def suffix
  self[range.last+1..-1]
end