Class: XCPretty::Snippet

Inherits:
Object
  • Object
show all
Defined in:
lib/xcpretty/snippet.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(contents = '', file_path = '') ⇒ Snippet

Returns a new instance of Snippet.



5
6
7
8
# File 'lib/xcpretty/snippet.rb', line 5

def initialize(contents = '', file_path = '')
  @contents = contents
  @file_path = file_path
end

Instance Attribute Details

#contentsObject (readonly)

Returns the value of attribute contents.



3
4
5
# File 'lib/xcpretty/snippet.rb', line 3

def contents
  @contents
end

#file_pathObject (readonly)

Returns the value of attribute file_path.



3
4
5
# File 'lib/xcpretty/snippet.rb', line 3

def file_path
  @file_path
end

Class Method Details

.from_filepath(filepath) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# 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