Sha256: 856b3b9514bd8b5b8740c0dbf655cc938fb5811e45cd172a3519b1051d0b2b13

Contents?: true

Size: 711 Bytes

Versions: 26

Compression:

Stored size: 711 Bytes

Contents

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
      new(text, filepath)
    rescue
      new('', filepath)
    end


    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

    def self.readline(file)
      file.gets
      $_ || ''
    end

  end
end

Version data entries

26 entries across 26 versions & 3 rubygems

Version Path
xcpretty-0.4.0 lib/xcpretty/snippet.rb
xcpretty-security-patched-0.3.2 lib/xcpretty/snippet.rb
xcpretty-security-patched-0.3.0 lib/xcpretty/snippet.rb
xcpretty-0.3.0 lib/xcpretty/snippet.rb
xcpretty-0.2.8 lib/xcpretty/snippet.rb
xcpretty-0.2.7 lib/xcpretty/snippet.rb
xcpretty-0.2.6 lib/xcpretty/snippet.rb
xcpretty-0.2.4 lib/xcpretty/snippet.rb
xcpretty-0.2.3 lib/xcpretty/snippet.rb
xcpretty-bb-0.1.12.bb14 lib/xcpretty/snippet.rb
xcpretty-bb-0.1.12.bb13 lib/xcpretty/snippet.rb
xcpretty-bb-0.1.12.bb12 lib/xcpretty/snippet.rb
xcpretty-bb-0.1.12.bb11 lib/xcpretty/snippet.rb
xcpretty-bb-0.1.12.bb10 lib/xcpretty/snippet.rb
xcpretty-bb-0.1.12.bb9 lib/xcpretty/snippet.rb
xcpretty-bb-0.1.12.bb8 lib/xcpretty/snippet.rb
xcpretty-0.2.2 lib/xcpretty/snippet.rb
xcpretty-bb-0.1.12.bb7 lib/xcpretty/snippet.rb
xcpretty-0.2.1 lib/xcpretty/snippet.rb
xcpretty-bb-0.1.12.bb6 lib/xcpretty/snippet.rb