Class Scanf::FormatSpecifier::FormatString
In: scanf.rb
Parent: Object

Methods

last_spec   match   new   prune   spec_count   to_s  

Constants

SPECIFIERS = 'diuXxofeEgsc'
REGEX = / # possible space, followed by... (?:\s* # percent sign, followed by... % # another percent sign, or... (?:%| # optional assignment suppression flag \*? # optional maximum field width \d* # named character class, ... (?:\[\[:\w+:\]\]| # traditional character class, or... \[[^\]]*\]| # specifier letter. [#{SPECIFIERS}])))| # or miscellaneous characters [^%\s]+/ix

Attributes

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

Public Class methods

[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

[Source]

# File scanf.rb, line 535
    def last_spec
      @i == spec_count - 1
    end

[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

[Source]

# File scanf.rb, line 527
    def prune(n=matched_count)
      n.times { @specs.shift }
    end

[Source]

# File scanf.rb, line 531
    def spec_count
      @specs.size
    end

[Source]

# File scanf.rb, line 523
    def to_s
      @specs.join('')
    end

[Validate]