Class: ABNF::Parser::Node::Sequence

Inherits:
Object
  • Object
show all
Includes:
ABNF::Parser::Node, Enumerable
Defined in:
lib/abnf/parser/node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ABNF::Parser::Node

#==, #[], alternation, #child_count, concatenation, #each, #octets, pattern_match, repetition, terminal

Constructor Details

#initialize(children, abnf) ⇒ Sequence

Returns a new instance of Sequence.



74
75
76
77
# File 'lib/abnf/parser/node.rb', line 74

def initialize children, abnf
  @abnf = abnf
  @children = children
end

Instance Attribute Details

#abnfObject (readonly)

Returns the value of attribute abnf.



71
72
73
# File 'lib/abnf/parser/node.rb', line 71

def abnf
  @abnf
end

#childrenObject (readonly)

Returns the value of attribute children.



72
73
74
# File 'lib/abnf/parser/node.rb', line 72

def children
  @children
end

Instance Method Details

#add(child) ⇒ Object Also known as: <<



79
80
81
# File 'lib/abnf/parser/node.rb', line 79

def add child
  children << child
end

#textObject



84
85
86
# File 'lib/abnf/parser/node.rb', line 84

def text
  @text ||= to_a.join
end

#to_aObject



88
89
90
91
92
93
94
95
96
# File 'lib/abnf/parser/node.rb', line 88

def to_a
  map do |child|
    if child.respond_to? :to_a
      child.to_a
    else
      child.text
    end
  end
end