Class: DiffParser::RawLine
- Inherits:
-
Object
- Object
- DiffParser::RawLine
- Defined in:
- lib/diff_parser/raw_line.rb
Constant Summary collapse
- GIT_NEW_FILE =
'new file'
- GIT_DELETED_FILE =
'deleted file'
- GIT_DIFF_START =
'+#!idiff-start!#++'
- GIT_DIFF_FINISH =
'-#!idiff-start!#--'
- GIT_INDEX =
'index '
- GIT_DIFF =
'diff --git '
- GIT_WARN_NEW_LINE =
' No newline at end of file'
- GIT_CODE_ADDED =
'+'
- GIT_CODE_REMOVED =
'-'
- SUMMARY_REGEXES =
[/^\-\-\- \/dev\/null/, /^\+\+\+ \/dev\/null/, /^\-\-\- a/, /^\+\+\+ b/]
Instance Attribute Summary collapse
-
#line ⇒ Object
readonly
Returns the value of attribute line.
Instance Method Summary collapse
- #addition? ⇒ Boolean
- #deletion? ⇒ Boolean
- #full_line ⇒ Object
- #index? ⇒ Boolean
- #info? ⇒ Boolean
-
#initialize(line) ⇒ RawLine
constructor
A new instance of RawLine.
- #skip_line? ⇒ Boolean
- #summary? ⇒ Boolean
- #type ⇒ Object
Constructor Details
#initialize(line) ⇒ RawLine
Returns a new instance of RawLine.
20 21 22 |
# File 'lib/diff_parser/raw_line.rb', line 20 def initialize(line) @line = line end |
Instance Attribute Details
#line ⇒ Object (readonly)
Returns the value of attribute line.
18 19 20 |
# File 'lib/diff_parser/raw_line.rb', line 18 def line @line end |
Instance Method Details
#addition? ⇒ Boolean
42 43 44 |
# File 'lib/diff_parser/raw_line.rb', line 42 def addition? line[0] == '+' end |
#deletion? ⇒ Boolean
46 47 48 |
# File 'lib/diff_parser/raw_line.rb', line 46 def deletion? line[0] == '-' end |
#full_line ⇒ Object
24 25 26 |
# File 'lib/diff_parser/raw_line.rb', line 24 def full_line @full_line ||= html_escape(line.gsub(/\n/, '')) end |
#index? ⇒ Boolean
38 39 40 |
# File 'lib/diff_parser/raw_line.rb', line 38 def index? type == 'index' end |
#info? ⇒ Boolean
34 35 36 |
# File 'lib/diff_parser/raw_line.rb', line 34 def info? type == 'info' end |
#skip_line? ⇒ Boolean
50 51 52 |
# File 'lib/diff_parser/raw_line.rb', line 50 def skip_line? summary? or %w(file_update_removed file_update_created).include?(type) end |
#summary? ⇒ Boolean
28 29 30 31 32 |
# File 'lib/diff_parser/raw_line.rb', line 28 def summary? SUMMARY_REGEXES.any? do |regex| line.match(regex) end end |
#type ⇒ Object
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 |
# File 'lib/diff_parser/raw_line.rb', line 54 def type if stripped_line.match(/^@@ -/) 'match' elsif stripped_line.start_with? GIT_NEW_FILE 'file_created' elsif stripped_line.start_with? GIT_DELETED_FILE 'file_removed' elsif stripped_line.start_with? GIT_DIFF_START 'file_update_created' elsif stripped_line.start_with? GIT_DIFF_FINISH 'file_update_removed' elsif stripped_line.start_with? GIT_INDEX 'index' elsif stripped_line.start_with? GIT_DIFF 'info' elsif stripped_line.start_with? GIT_WARN_NEW_LINE 'warning' elsif stripped_line.start_with? GIT_CODE_ADDED 'new' elsif line[0] == GIT_CODE_REMOVED 'old' else 'default' end end |