Class: Cucumber::Core::Ast::Location

Inherits:
Struct
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/cucumber/core/ast/location.rb

Defined Under Namespace

Classes: FilePath, Lines

Constant Summary collapse

WILDCARD =
:*

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filepath, raw_lines = WILDCARD) ⇒ Location

Returns a new instance of Location.



21
22
23
24
# File 'lib/cucumber/core/ast/location.rb', line 21

def initialize(filepath, raw_lines=WILDCARD)
  filepath || raise(ArgumentError, "file is mandatory")
  super(FilePath.new(filepath), Lines.new(raw_lines))
end

Instance Attribute Details

#filepathObject

Returns the value of attribute filepath

Returns:

  • (Object)

    the current value of filepath



6
7
8
# File 'lib/cucumber/core/ast/location.rb', line 6

def filepath
  @filepath
end

#linesObject

Returns the value of attribute lines

Returns:

  • (Object)

    the current value of lines



6
7
8
# File 'lib/cucumber/core/ast/location.rb', line 6

def lines
  @lines
end

Class Method Details

.of_callerObject



16
17
18
19
# File 'lib/cucumber/core/ast/location.rb', line 16

def self.of_caller
  file, raw_line = *caller[1].split(':')[0..1]
  new(file, raw_line.to_i)
end

Instance Method Details

#hashObject



34
35
36
# File 'lib/cucumber/core/ast/location.rb', line 34

def hash
  self.class.hash ^ to_s.hash
end

#inspectObject



46
47
48
# File 'lib/cucumber/core/ast/location.rb', line 46

def inspect
  "<#{self.class}: #{to_s}>"
end

#match?(other) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/cucumber/core/ast/location.rb', line 26

def match?(other)
  other.same_as?(filepath) && other.include?(lines)
end

#on_line(new_line) ⇒ Object



42
43
44
# File 'lib/cucumber/core/ast/location.rb', line 42

def on_line(new_line)
  Location.new(filepath.filename, new_line)
end

#to_sObject



30
31
32
# File 'lib/cucumber/core/ast/location.rb', line 30

def to_s
  [filepath.to_s, lines.to_s].reject { |v| v == WILDCARD.to_s }.join(":")
end

#to_strObject



38
39
40
# File 'lib/cucumber/core/ast/location.rb', line 38

def to_str
  to_s
end