lib/xcpretty/snippet.rb in xcpretty-0.1.7 vs lib/xcpretty/snippet.rb in xcpretty-0.1.8
- old
+ new
@@ -1,24 +1,30 @@
module XCPretty
class Snippet
+ attr_reader :contents, :file_path
+ def initialize(contents = '', file_path = '')
+ @contents = contents
+ @file_path = file_path
+ end
+
def self.from_filepath(filepath)
path, line = filepath.split(':')
file = File.open(path)
text = read_snippet(file, line)
file.close
- text
+ new(text, filepath)
rescue
- ''
+ new('', filepath)
end
private
def self.read_snippet(file, around_line)
- text = ""
+ text = ''
starting_position = around_line.to_i - 2
starting_position.times { file.gets }
3.times { text += readline(file) }
text
end