Class: Dms::Tier1::SingleValueParser

Inherits:
Object
  • Object
show all
Defined in:
lib/dms/tier1.rb

Overview

SingleValueParser: uses Dms::Parser to parse one value from a string.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(src) ⇒ SingleValueParser

Returns a new instance of SingleValueParser.



1644
1645
1646
1647
1648
# File 'lib/dms/tier1.rb', line 1644

def initialize(src)
  @src = src
  @parser = nil
  @consumed = 0
end

Instance Attribute Details

#consumedObject (readonly)

Returns the value of attribute consumed.



1642
1643
1644
# File 'lib/dms/tier1.rb', line 1642

def consumed
  @consumed
end

Instance Method Details

#parse_value_at_startObject



1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
# File 'lib/dms/tier1.rb', line 1650

def parse_value_at_start
  # Wrap in a minimal DMS document and parse, then extract the value.
  # Since we need to parse a raw value (not a key-value pair),
  # we wrap it as `_v: <value>` and parse the front matter.
  # Actually simpler: parse as a scalar root document.

  # Build: the value might be followed by sigil chars, newlines, etc.
  # We'll use a fresh Parser at lite mode.
  p = Dms::Parser.new(@src, lite: true)
  val = p.parse_inline_value_or_heredoc
  @consumed = p.instance_variable_get(:@pos)
  val
end