Class: String
- Inherits:
-
Object
- Object
- String
- 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
-
#added_range ⇒ Object
Returns the value of attribute added_range.
-
#removed_range ⇒ Object
Returns the value of attribute removed_range.
Instance Method Summary collapse
- #added ⇒ Object
- #added? ⇒ Boolean
- #common_prefix_length(o) ⇒ Object
- #content ⇒ Object
- #html_encoded ⇒ Object
- #prefix ⇒ Object
- #removed ⇒ Object
- #removed? ⇒ Boolean
- #suffix ⇒ Object
Instance Attribute Details
#added_range ⇒ Object
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_range ⇒ Object
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
#added ⇒ Object
111 112 113 |
# File 'lib/damagecontrol/diff_parser.rb', line 111 def added added_range ? self[added_range] : nil end |
#added? ⇒ 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 |
#content ⇒ Object
123 124 125 |
# File 'lib/damagecontrol/diff_parser.rb', line 123 def content "\n" == self ? "\n" : self[1..-1] end |
#html_encoded ⇒ Object
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 "<" when ">" then ">" else $& end end end |
#prefix ⇒ Object
115 116 117 |
# File 'lib/damagecontrol/diff_parser.rb', line 115 def prefix self[0..range.first-1] end |
#removed ⇒ Object
103 104 105 |
# File 'lib/damagecontrol/diff_parser.rb', line 103 def removed removed_range ? self[removed_range] : nil end |
#removed? ⇒ Boolean
99 100 101 |
# File 'lib/damagecontrol/diff_parser.rb', line 99 def removed? (self =~ /\-/) == 0 end |
#suffix ⇒ Object
119 120 121 |
# File 'lib/damagecontrol/diff_parser.rb', line 119 def suffix self[range.last+1..-1] end |