Class: Kwalify::PlainYamlParser

Inherits:
Object
  • Object
show all
Defined in:
lib/kwalify/yaml-parser.rb

Overview

base class of yaml parser

ex.

str = ARGF.read()
parser = Kwalify::PlainYamlParser.new(str)
doc = parser.parse()
p doc

Direct Known Subclasses

YamlParser

Defined Under Namespace

Classes: Alias

Instance Method Summary collapse

Constructor Details

#initialize(yaml_str) ⇒ PlainYamlParser

Returns a new instance of PlainYamlParser.



36
37
38
39
40
41
42
# File 'lib/kwalify/yaml-parser.rb', line 36

def initialize(yaml_str)
  @lines = yaml_str.to_a()
  @line  = nil
  @linenum = 0
  @anchors = {}
  @aliases = {}
end

Instance Method Details

#has_next?Boolean

Returns:



55
56
57
# File 'lib/kwalify/yaml-parser.rb', line 55

def has_next?
  return @end_flag != 'EOF'
end

#parseObject



45
46
47
48
49
50
51
52
# File 'lib/kwalify/yaml-parser.rb', line 45

def parse()
  data = parse_child(0)
  if data.nil? && @end_flag == '---'
    data = parse_child(0)
  end
  resolve_aliases(data) unless @aliases.empty?
  return data
end

#parse_allObject



60
61
62
63
64
65
66
67
# File 'lib/kwalify/yaml-parser.rb', line 60

def parse_all
  list = []
  while has_next()
    doc = parse()
    list << doc
  end
  return list
end