Module: BlackStack::Strings::Spinning
- Defined in:
- lib/functions.rb
Overview
Spinning
Class Method Summary collapse
-
.random_spinning_variation(text) ⇒ Object
Esta funcion retorna una variacion al azar del texto que se pasa.
-
.spintax?(s) ⇒ Boolean
returns true if the text is spinned.
-
.valid_spinning_syntax?(s) ⇒ Boolean
retorna true si la sintaxis del texto spineado es correcta caso contrario retorna false no soporta spinnings anidados.
Class Method Details
.random_spinning_variation(text) ⇒ Object
Esta funcion retorna una variacion al azar del texto que se pasa. Esta funcion se ocupa de dividir el texto en partes, para eviar el error “too big to product” que arroja la libraría.
673 674 675 676 677 678 679 680 681 682 683 684 |
# File 'lib/functions.rb', line 673 def self.random_spinning_variation(text) ret = text text.scan(MATCH_CONTENT_SPINNING).each { |s| a = ContentSpinning.new(s).spin rep = a[rand(a.size)] ret = ret.gsub(s, rep) a = nil } return ret end |
.spintax?(s) ⇒ Boolean
returns true if the text is spinned. otherwise, returns false.
716 717 718 |
# File 'lib/functions.rb', line 716 def self.spintax?(s) s.scan(MATCH_CONTENT_SPINNING).size > 0 end |
.valid_spinning_syntax?(s) ⇒ Boolean
retorna true si la sintaxis del texto spineado es correcta caso contrario retorna false no soporta spinnings anidados. ejemplo: car of mine}
689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 |
# File 'lib/functions.rb', line 689 def self.valid_spinning_syntax?(s) # valido que exste n = 0 s.split('').each { |c| n+=1 if c=='{' n-=1 if c=='}' if n!=0 && n!=1 #raise "Closing spining char '}' with not previous opening spining char '{'." if n<0 #raise "Opening spining char '{' inside another spining block." if n>1 return false if n<0 # Closing spining char '}' with not previous opening spining char '{'. return false if n>1 # Opening spining char '{' inside another spining block. end } return false if n!=0 =begin # obtengo cada uno de los spinnings s.scan(MATCH_CONTENT_SPINNING).each { |x| a = x.split('|') raise "No variations delimited by '|' inside spinning block." if a.size <= 1 } =end true end |