Extended maintenance of Ruby versions 1.8.7 and 1.9.2 ended on July 31, 2014. Read more

In Files

  • scanf.rb

Parent

Class/Module Index [+]

Quicksearch

Scanf::FormatString

Constants

REGEX
SPECIFIERS

Attributes

last_match_tried[R]
last_spec_tried[R]
matched_count[R]
space[R]
string_left[R]

Public Class Methods

new(str) click to toggle source
 
               # File scanf.rb, line 514
def initialize(str)
  @specs = []
  @i = 1
  s = str.to_s
  return unless /\S/.match(s)
  @space = true if /\s\z/.match(s)
  @specs.replace s.scan(REGEX).map {|spec| FormatSpecifier.new(spec) }
end
            

Public Instance Methods

last_spec() click to toggle source
 
               # File scanf.rb, line 535
def last_spec
  @i == spec_count - 1
end
            
match(str) click to toggle source
 
               # File scanf.rb, line 539
def match(str)
  accum = []
  @string_left = str
  @matched_count = 0

  @specs.each_with_index do |spec,@i|
    @last_spec_tried = spec
    @last_match_tried = spec.match(@string_left)
    break unless @last_match_tried
    @matched_count += 1

    accum << spec.conversion

    @string_left = @last_match_tried.post_match
    break if @string_left.empty?
  end
  return accum.compact
end
            
prune(n=matched_count) click to toggle source
 
               # File scanf.rb, line 527
def prune(n=matched_count)
  n.times { @specs.shift }
end
            
spec_count() click to toggle source
 
               # File scanf.rb, line 531
def spec_count
  @specs.size
end
            
to_s() click to toggle source
 
               # File scanf.rb, line 523
def to_s
  @specs.join('')
end