# Scanf::FormatSpecifier::FormatString (Class)

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

new(str)

[Source]

    # File scanf.rb, line 516
        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

to_s()

[Source]

    # File scanf.rb, line 525
        def to_s
          @spec_string
        end

prune(n=matched_count)

[Source]

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

spec_count()

[Source]

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

last_spec()

[Source]

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

match(str)

[Source]

    # File scanf.rb, line 541
        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

[Validate]