Class: Svn::UnifiedDiff

Inherits:
Array
  • Object
show all
Defined in:
lib/Svn/mime_type.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(diff, options = {}) ⇒ UnifiedDiff

Returns a new instance of UnifiedDiff.



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/Svn/mime_type.rb', line 94

def initialize(diff, options={})
	options.assert_valid_keys(:type, :style, :max_lines)
	diff = diff.split("\n") if diff.is_a?(String)
	@diff_type = options[:type] || 'inline'
	@diff_style = options[:style]
	lines = 0
	@truncated = false
	diff_table = DiffTable.new(diff_type, diff_style)
	diff.each do |line_raw|
		line = Svn::CodesetUtil.to_utf8_by_setting(line_raw)
		unless diff_table.add_line(line)
			self << diff_table if diff_table.length > 0
			diff_table = DiffTable.new(diff_type, diff_style)
		end
		lines += 1
		if options[:max_lines] && lines > options[:max_lines]
			@truncated = true
			break
		end
	end
	self << diff_table unless diff_table.empty?
	self
end

Instance Attribute Details

#diff_styleObject (readonly)

Returns the value of attribute diff_style.



92
93
94
# File 'lib/Svn/mime_type.rb', line 92

def diff_style
  @diff_style
end

#diff_typeObject (readonly)

Returns the value of attribute diff_type.



92
93
94
# File 'lib/Svn/mime_type.rb', line 92

def diff_type
  @diff_type
end

Instance Method Details

#truncated?Boolean

Returns:

  • (Boolean)


117
# File 'lib/Svn/mime_type.rb', line 117

def truncated?; @truncated; end