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|
    @i=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
            

Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.

If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.

blog comments powered by Disqus