Class: PMLCode::Source

Inherits:
Object
  • Object
show all
Defined in:
lib/pmlcode/source.rb

Constant Summary collapse

PATTERN =
/^(?<path>.+?)(:(?<line>\d+):?)?$/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, line) ⇒ Source

Returns a new instance of Source.



12
13
14
15
# File 'lib/pmlcode/source.rb', line 12

def initialize(path, line)
  @path = File.expand_path(path)
  @line = line
end

Instance Attribute Details

#lineObject (readonly)

Returns the value of attribute line.



11
12
13
# File 'lib/pmlcode/source.rb', line 11

def line
  @line
end

#pathObject (readonly)

Returns the value of attribute path.



11
12
13
# File 'lib/pmlcode/source.rb', line 11

def path
  @path
end

Class Method Details

.parse(text) ⇒ Object



5
6
7
8
9
# File 'lib/pmlcode/source.rb', line 5

def self.parse(text)
  if (match = text.match(PATTERN))
    new(match[:path], match[:line] ? Integer(match[:line]) : nil)
  end
end

Instance Method Details

#missing?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/pmlcode/source.rb', line 17

def missing?
  !File.exists?(@path)
end

#to_sObject



21
22
23
# File 'lib/pmlcode/source.rb', line 21

def to_s
  [@path, @line].join(":")
end