class XCPretty::Snippet

Attributes

contents[R]
file_path[R]

Public Class Methods

from_filepath(filepath) click to toggle source
# File lib/xcpretty/snippet.rb, line 10
def self.from_filepath(filepath)
  path, line = filepath.split(':')
  file = File.open(path)

  text = read_snippet(file, line)

  file.close
  new(text, filepath)
rescue
  new('', filepath)
end
new(contents = '', file_path = '') click to toggle source
# File lib/xcpretty/snippet.rb, line 5
def initialize(contents = '', file_path = '')
  @contents = contents
  @file_path = file_path
end
read_snippet(file, around_line) click to toggle source
# File lib/xcpretty/snippet.rb, line 23
def self.read_snippet(file, around_line)
  text = ''
  starting_position = around_line.to_i - 2
  starting_position.times { file.gets }
  3.times { text += readline(file) }
  text
end
readline(file) click to toggle source
# File lib/xcpretty/snippet.rb, line 31
def self.readline(file)
  file.gets
  $_ || ''
end