Class: Scanf::FormatString
Do not use. This class is for internal use only.
Relationships & Source Files | |
Inherits: | Object |
Defined in: | lib/scanf.rb |
Constant Summary
-
REGEX =
# File 'lib/scanf.rb', line 495/ # 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
-
SPECIFIERS =
# File 'lib/scanf.rb', line 494'diuXxofFeEgGscaA'
Class Method Summary
- .new(str) ⇒ FormatString constructor
Instance Attribute Summary
- #last_match_tried readonly
- #last_spec_tried readonly
- #matched_count readonly
- #space readonly
- #string_left readonly
Instance Method Summary
Constructor Details
.new(str) ⇒ FormatString
Instance Attribute Details
#last_match_tried (readonly)
[ GitHub ]# File 'lib/scanf.rb', line 491
attr_reader :string_left, :last_spec_tried, :last_match_tried, :matched_count, :space
#last_spec_tried (readonly)
[ GitHub ]# File 'lib/scanf.rb', line 491
attr_reader :string_left, :last_spec_tried, :last_match_tried, :matched_count, :space
#matched_count (readonly)
[ GitHub ]# File 'lib/scanf.rb', line 491
attr_reader :string_left, :last_spec_tried, :last_match_tried, :matched_count, :space
#space (readonly)
[ GitHub ]# File 'lib/scanf.rb', line 491
attr_reader :string_left, :last_spec_tried, :last_match_tried, :matched_count, :space
#string_left (readonly)
[ GitHub ]# File 'lib/scanf.rb', line 491
attr_reader :string_left, :last_spec_tried, :last_match_tried, :matched_count, :space
Instance Method Details
#last_spec
[ GitHub ]# File 'lib/scanf.rb', line 536
def last_spec @i == spec_count - 1 end
#match(str)
[ GitHub ]# File 'lib/scanf.rb', line 540
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)
[ GitHub ]# File 'lib/scanf.rb', line 528
def prune(n=matched_count) n.times { @specs.shift } end
#spec_count
[ GitHub ]# File 'lib/scanf.rb', line 532
def spec_count @specs.size end
#to_s
[ GitHub ]# File 'lib/scanf.rb', line 524
def to_s @specs.join('') end