Class: Fixturex::FixtureLocation

Inherits:
Object
  • Object
show all
Defined in:
lib/fixturex/fixture_location.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, name, line = nil) ⇒ FixtureLocation

Returns a new instance of FixtureLocation.



5
6
7
8
9
# File 'lib/fixturex/fixture_location.rb', line 5

def initialize(path, name, line = nil)
  @path = path
  @name = name
  @line = line
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/fixturex/fixture_location.rb', line 3

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



3
4
5
# File 'lib/fixturex/fixture_location.rb', line 3

def path
  @path
end

Instance Method Details

#lineObject



11
12
13
14
15
# File 'lib/fixturex/fixture_location.rb', line 11

def line
  @line ||= File.readlines(path).index do |line|
    line.match?(/^#{Regexp.escape(name)}:/)
  end + 1
end

#to_hObject



17
18
19
20
21
22
23
# File 'lib/fixturex/fixture_location.rb', line 17

def to_h
  {
    name: name,
    path: path.to_s,
    line: line
  }
end