Class: ABNF::Parser::Rules::Concatenation

Inherits:
Object
  • Object
show all
Defined in:
lib/abnf/parser/rules/concatenation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rules, abnf) ⇒ Concatenation

Returns a new instance of Concatenation.



8
9
10
11
# File 'lib/abnf/parser/rules/concatenation.rb', line 8

def initialize rules, abnf
  @abnf = abnf
  @rules = rules
end

Instance Attribute Details

#abnfObject (readonly)

Returns the value of attribute abnf.



5
6
7
# File 'lib/abnf/parser/rules/concatenation.rb', line 5

def abnf
  @abnf
end

#rulesObject (readonly)

Returns the value of attribute rules.



6
7
8
# File 'lib/abnf/parser/rules/concatenation.rb', line 6

def rules
  @rules
end

Instance Method Details

#==(other_rule) ⇒ Object



13
14
15
16
# File 'lib/abnf/parser/rules/concatenation.rb', line 13

def == other_rule
  return false unless other_rule.is_a? self.class
  self.rules == other_rule.rules
end

#call(io, rule_list = nil) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/abnf/parser/rules/concatenation.rb', line 18

def call io, rule_list=nil
  node = Node.concatenation abnf

  match = rules.all? do |rule|
    child = rule.(io, rule_list) or break
    node << child
  end

  if match
    node
  else
    io.seek -node.octets, IO::SEEK_CUR
    nil
  end
end