Method: Parsey::ScanArray#each_with_type

Defined in:
lib/parsey.rb

#each_with_type {|Symbol, Object| ... } ⇒ StringScanner

Loops through the types and contents of each tag separately, passing them to the block given.

Examples:


sa = ScanArray.new([[:text, 'hey-'], 
                    [:optional, 
                      [[:block, '([a-z]+)'], 
                       [:text, '-what']]
                   ]])

sa.each_with_type do |type, content|
  puts "#{type} -> #{content}"
end
#=> text -> hey-
#=> optional -> [[:block, "([a-z]+)"], [:text, "-what"]]

Yields:

  • (Symbol, Object)

    gives the type and content of each block in turn

Returns:

  • (StringScanner)

    returns self



295
296
297
298
299
300
301
302
# File 'lib/parsey.rb', line 295

def each_with_type(&blck)
  ts = self.collect {|i| i[0]}
  cs = self.collect {|i| i[1]}
  (0...ts.size).each do |i|
    yield(ts[i], cs[i])
  end
  self
end