Class: Puppet::Pops::Adapters::SourcePosAdapter

Inherits:
Puppet::Pops::Adaptable::Adapter show all
Defined in:
lib/puppet/pops/adapters.rb

Overview

A SourcePosAdapter describes a position relative to an origin. (Typically an OriginAdapter is associated with the root of a model. This origin has a URI to the resource, and a line number. The offset in the SourcePosAdapter is then relative to this origin. (This somewhat complex structure makes it possible to correctly refer to a source position in source that is embedded in some resource; a parser only sees the embedded snippet of source text and does not know where it was embedded).

See Also:

  • Utils#find_adapter

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Puppet::Pops::Adaptable::Adapter

adapt, adapt_new, associate_adapter, clear, create_adapter, get, instance_var_name

Instance Attribute Details

#lengthFixnum

Returns The length (count) of characters of source text representing the adapted object from the origin. Not including any trailing whitespace.

Returns:

  • (Fixnum)

    The length (count) of characters of source text representing the adapted object from the origin. Not including any trailing whitespace.



49
50
51
# File 'lib/puppet/pops/adapters.rb', line 49

def length
  @length
end

#lineFixnum

Returns The start line in source starting from 1.

Returns:

  • (Fixnum)

    The start line in source starting from 1



36
37
38
# File 'lib/puppet/pops/adapters.rb', line 36

def line
  @line
end

#offsetFixnum

Returns The (start) offset of source text characters (starting from 0) representing the adapted object. Value may be nil.

Returns:

  • (Fixnum)

    The (start) offset of source text characters (starting from 0) representing the adapted object. Value may be nil



44
45
46
# File 'lib/puppet/pops/adapters.rb', line 44

def offset
  @offset
end

#posFixnum

Returns The position on the start_line (in characters) starting from 0.

Returns:

  • (Fixnum)

    The position on the start_line (in characters) starting from 0



39
40
41
# File 'lib/puppet/pops/adapters.rb', line 39

def pos
  @pos
end

Instance Method Details

#extract_text_from_string(string) ⇒ Object



51
52
53
# File 'lib/puppet/pops/adapters.rb', line 51

def extract_text_from_string(string)
  string.slice(offset, length)
end