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.



1676
1677
1678
1679
1680
# File 'lib/dms/tier1.rb', line 1676

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

Instance Attribute Details

#consumedObject (readonly)

Returns the value of attribute consumed.



1674
1675
1676
# File 'lib/dms/tier1.rb', line 1674

def consumed
  @consumed
end

Instance Method Details

#parse_value_at_startObject



1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
# File 'lib/dms/tier1.rb', line 1682

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