Class Scanf::FormatString
In: lib/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 lib/scanf.rb, line 514
514:     def initialize(str)
515:       @specs = []
516:       @i = 1
517:       s = str.to_s
518:       return unless /\S/.match(s)
519:       @space = true if /\s\z/.match(s)
520:       @specs.replace s.scan(REGEX).map {|spec| FormatSpecifier.new(spec) }
521:     end

Public Instance methods

[Source]

     # File lib/scanf.rb, line 535
535:     def last_spec
536:       @i == spec_count - 1
537:     end

[Source]

     # File lib/scanf.rb, line 539
539:     def match(str)
540:       accum = []
541:       @string_left = str
542:       @matched_count = 0
543: 
544:       @specs.each_with_index do |spec,@i|
545:         @last_spec_tried = spec
546:         @last_match_tried = spec.match(@string_left)
547:         break unless @last_match_tried
548:         @matched_count += 1
549: 
550:         accum << spec.conversion
551: 
552:         @string_left = @last_match_tried.post_match
553:         break if @string_left.empty?
554:       end
555:       return accum.compact
556:     end

[Source]

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

[Source]

     # File lib/scanf.rb, line 531
531:     def spec_count
532:       @specs.size
533:     end

[Source]

     # File lib/scanf.rb, line 523
523:     def to_s
524:       @specs.join('')
525:     end

[Validate]