Class: Rpatch::Pattern
- Inherits:
-
Object
- Object
- Rpatch::Pattern
- Defined in:
- lib/rpatch/hunk.rb
Instance Attribute Summary collapse
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Instance Method Summary collapse
-
#initialize(line) ⇒ Pattern
constructor
A new instance of Pattern.
- #is_add? ⇒ Boolean
- #is_in_after? ⇒ Boolean
- #is_in_before? ⇒ Boolean
- #is_pattern? ⇒ Boolean
- #match(message) ⇒ Object
- #pattern ⇒ Object
Constructor Details
#initialize(line) ⇒ Pattern
Returns a new instance of Pattern.
8 9 10 |
# File 'lib/rpatch/hunk.rb', line 8 def initialize(line) @text = line.chomp end |
Instance Attribute Details
#text ⇒ Object (readonly)
Returns the value of attribute text.
6 7 8 |
# File 'lib/rpatch/hunk.rb', line 6 def text @text end |
Instance Method Details
#is_add? ⇒ Boolean
24 25 26 27 28 |
# File 'lib/rpatch/hunk.rb', line 24 def is_add? @is_add ||= begin @text =~ /^\+/ end end |
#is_in_after? ⇒ Boolean
18 19 20 21 22 |
# File 'lib/rpatch/hunk.rb', line 18 def is_in_after? @is_in_after ||= begin @text =~ /^( |\+|\/ |\/\+)/ end end |
#is_in_before? ⇒ Boolean
12 13 14 15 16 |
# File 'lib/rpatch/hunk.rb', line 12 def is_in_before? @is_in_before ||= begin @text =~ /^( |-|\/ |\/-|\? |\?-|\?\/ |\?\/-)/ end end |
#is_pattern? ⇒ Boolean
30 31 32 |
# File 'lib/rpatch/hunk.rb', line 30 def is_pattern? @is_pattern ||= pattern.is_a?(Regexp) end |
#match(message) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/rpatch/hunk.rb', line 50 def match() return nil unless = .chomp match = nil while true if is_pattern? # When match with regexp, do not twick message if pattern.match() match = 1 end else = .strip.gsub(/\s+/, ' ') if pattern == match = 1 end end if match break elsif .empty? match = 0 break # compare without leading "#" elsif .start_with? "#" while .start_with? "#" = [1..-1] = .strip unless is_pattern? end else break end end match end |
#pattern ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/rpatch/hunk.rb', line 34 def pattern @pattern ||= begin if text =~ /^\/( |-|\+)/ Regexp.new(text[2..-1].strip) elsif text =~ /^\?\/( |-|\+)/ Regexp.new(text[3..-1].strip) elsif text =~ /^( |-|\+)/ pattern = text[1..-1].strip.gsub(/\s+/, ' ') elsif text =~ /^\?( |-|\+)/ pattern = text[2..-1].strip.gsub(/\s+/, ' ') else raise PatchFormatError.new("-0---Unknown pattern in diffs: #{text.inspect}") end end end |