Class: RSpec::Covers::CodeRegion
- Inherits:
-
Object
- Object
- RSpec::Covers::CodeRegion
- Defined in:
- lib/rspec/covers/code_location.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#lines ⇒ Object
readonly
Returns the value of attribute lines.
Class Method Summary collapse
Instance Method Summary collapse
- #include?(location) ⇒ Boolean
-
#initialize(file:, lines:, label:) ⇒ CodeRegion
constructor
A new instance of CodeRegion.
- #locations ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(file:, lines:, label:) ⇒ CodeRegion
Returns a new instance of CodeRegion.
20 21 22 23 24 |
# File 'lib/rspec/covers/code_location.rb', line 20 def initialize(file:, lines:, label:) @file = File.(file) @lines = Set.new(lines.map(&:to_i)) @label = label end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
18 19 20 |
# File 'lib/rspec/covers/code_location.rb', line 18 def file @file end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
18 19 20 |
# File 'lib/rspec/covers/code_location.rb', line 18 def label @label end |
#lines ⇒ Object (readonly)
Returns the value of attribute lines.
18 19 20 |
# File 'lib/rspec/covers/code_location.rb', line 18 def lines @lines end |
Class Method Details
.file(file, label: file) ⇒ Object
42 43 44 45 46 |
# File 'lib/rspec/covers/code_location.rb', line 42 def self.file(file, label: file) line_count = File.exist?(file) ? File.readlines(file).length : 0 new(file: file, lines: 1..line_count, label: label) end |
Instance Method Details
#include?(location) ⇒ Boolean
26 27 28 |
# File 'lib/rspec/covers/code_location.rb', line 26 def include?(location) file == File.(location.file) && lines.include?(location.line) end |
#locations ⇒ Object
30 31 32 |
# File 'lib/rspec/covers/code_location.rb', line 30 def locations lines.map { |line| CodeLocation.new(file: file, line: line) }.to_set end |
#to_h ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/rspec/covers/code_location.rb', line 34 def to_h { file: file, lines: lines.to_a.sort, label: label } end |