Class: AutoCorrect::Strategery
- Inherits:
-
Object
- Object
- AutoCorrect::Strategery
- Defined in:
- lib/auto-correct/strategery.rb
Instance Attribute Summary collapse
-
#add_space_rules ⇒ Object
readonly
Returns the value of attribute add_space_rules.
-
#remove_space_rules ⇒ Object
readonly
Returns the value of attribute remove_space_rules.
-
#reverse ⇒ Object
readonly
Returns the value of attribute reverse.
-
#space ⇒ Object
readonly
Returns the value of attribute space.
Instance Method Summary collapse
- #add_space(str) ⇒ Object
- #format(str) ⇒ Object
-
#initialize(one, other, space: false, reverse: false) ⇒ Strategery
constructor
A new instance of Strategery.
- #remove_space(str) ⇒ Object
Constructor Details
#initialize(one, other, space: false, reverse: false) ⇒ Strategery
Returns a new instance of Strategery.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/auto-correct/strategery.rb', line 6 def initialize(one, other, space: false, reverse: false) @space = space @reverse = reverse @add_space_rules = [ /(#{one})(#{other})/u, /(#{other})(#{one})/u ] @remove_space_rules = [ /(#{one})#{SPACE}+(#{other})/u, /(#{other})#{SPACE}+(#{one})/u ] end |
Instance Attribute Details
#add_space_rules ⇒ Object (readonly)
Returns the value of attribute add_space_rules.
4 5 6 |
# File 'lib/auto-correct/strategery.rb', line 4 def add_space_rules @add_space_rules end |
#remove_space_rules ⇒ Object (readonly)
Returns the value of attribute remove_space_rules.
4 5 6 |
# File 'lib/auto-correct/strategery.rb', line 4 def remove_space_rules @remove_space_rules end |
#reverse ⇒ Object (readonly)
Returns the value of attribute reverse.
3 4 5 |
# File 'lib/auto-correct/strategery.rb', line 3 def reverse @reverse end |
#space ⇒ Object (readonly)
Returns the value of attribute space.
3 4 5 |
# File 'lib/auto-correct/strategery.rb', line 3 def space @space end |
Instance Method Details
#add_space(str) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/auto-correct/strategery.rb', line 25 def add_space(str) r0, r1 = add_space_rules str = str.gsub(r0) { "#$1 #$2" } if self.reverse str = str.gsub(r1) { "#$1 #$2" } end str end |
#format(str) ⇒ Object
21 22 23 |
# File 'lib/auto-correct/strategery.rb', line 21 def format(str) self.space ? add_space(str) : remove_space(str) end |
#remove_space(str) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/auto-correct/strategery.rb', line 34 def remove_space(str) r0, r1 = remove_space_rules str = str.gsub(r0) { "#$1 #$2" } if self.reverse str = str.gsub(r1) { "#$1 #$2" } end str end |