Class: Getopt::Declare::Punctuator
- Inherits:
-
Object
- Object
- Getopt::Declare::Punctuator
- Defined in:
- lib/Getopt/Declare.rb
Overview
Class used to handle punctuations (., -, etc.)
Instance Method Summary collapse
-
#cachecode(ownerflag, itemcount) ⇒ Object
Return string with code to cache punctuation in Getopt::Declare’s cache.
-
#code(*t) ⇒ Object
Return string with code to process punctuation.
-
#initialize(text, nows) ⇒ Punctuator
constructor
Constructor.
-
#matcher(g) ⇒ Object
Return regex that matches this punctuation.
-
#ows(g) ⇒ Object
Helps build regex that matches parameters of flags Wraps parameter passed for #$1, etc.
-
#trailer ⇒ Object
Helps build regex that matches parameters of flags.
Constructor Details
#initialize(text, nows) ⇒ Punctuator
Constructor
410 411 412 413 |
# File 'lib/Getopt/Declare.rb', line 410 def initialize(text, nows) @text = text @nows = nows end |
Instance Method Details
#cachecode(ownerflag, itemcount) ⇒ Object
Return string with code to cache punctuation in Getopt::Declare’s cache
435 436 437 438 439 440 441 442 443 |
# File 'lib/Getopt/Declare.rb', line 435 def cachecode(ownerflag, itemcount) if itemcount > 1 " @cache['#{ownerflag}']['#{@text}'] = _PUNCT_['#{@text}']\n" else " unless @cache['#{ownerflag}']\n" + " @cache['#{ownerflag}'] = _PUNCT_['#{@text}'] || 1\n" + " end\n" end end |
#code(*t) ⇒ Object
Return string with code to process punctuation
421 422 423 424 425 426 427 428 429 430 431 432 |
# File 'lib/Getopt/Declare.rb', line 421 def code(*t) if t[0] pos1 = t[0].to_s else pos1 = '0' end " if @@m[#{pos1}] && !@@m[#{pos1}].empty? _PUNCT_['#{@text}'] = @@m[#{pos1}] end " end |
#matcher(g) ⇒ Object
Return regex that matches this punctuation
416 417 418 |
# File 'lib/Getopt/Declare.rb', line 416 def matcher(g) Arg::negflagpat + Regexp::quote(@text) end |
#ows(g) ⇒ Object
Helps build regex that matches parameters of flags Wraps parameter passed for #$1, etc. matching
452 453 454 455 |
# File 'lib/Getopt/Declare.rb', line 452 def ows(g) return '[\s\0]*(' + g + ')' unless @nows '(' + g + ')' end |
#trailer ⇒ Object
Helps build regex that matches parameters of flags
446 447 448 |
# File 'lib/Getopt/Declare.rb', line 446 def trailer @text end |