Class: ExtractI18n::HTMLExtractor::TwoWayRegexp
- Inherits:
-
Object
- Object
- ExtractI18n::HTMLExtractor::TwoWayRegexp
- Defined in:
- lib/extract_i18n/html_extractor/two_way_regexp.rb
Instance Attribute Summary collapse
-
#from ⇒ Object
readonly
Returns the value of attribute from.
-
#to ⇒ Object
readonly
Returns the value of attribute to.
Instance Method Summary collapse
-
#initialize(from, to) ⇒ TwoWayRegexp
constructor
A new instance of TwoWayRegexp.
- #inverse_replace(text) ⇒ Object
- #inverse_replace!(text) ⇒ Object
- #replace(text) ⇒ Object
- #replace!(text) ⇒ Object
Constructor Details
#initialize(from, to) ⇒ TwoWayRegexp
Returns a new instance of TwoWayRegexp.
6 7 8 9 |
# File 'lib/extract_i18n/html_extractor/two_way_regexp.rb', line 6 def initialize(from, to) @from = from @to = to end |
Instance Attribute Details
#from ⇒ Object (readonly)
Returns the value of attribute from.
4 5 6 |
# File 'lib/extract_i18n/html_extractor/two_way_regexp.rb', line 4 def from @from end |
#to ⇒ Object (readonly)
Returns the value of attribute to.
4 5 6 |
# File 'lib/extract_i18n/html_extractor/two_way_regexp.rb', line 4 def to @to end |
Instance Method Details
#inverse_replace(text) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/extract_i18n/html_extractor/two_way_regexp.rb', line 31 def inverse_replace(text) if block_given? text.gsub(@to) do |matched_text| yield(from_as_format, Regexp.last_match, matched_text) end else text.gsub(@to, reverse_from) end end |
#inverse_replace!(text) ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/extract_i18n/html_extractor/two_way_regexp.rb', line 41 def inverse_replace!(text) if block_given? text.gsub!(@to) do |matched_text| yield(from_as_format, Regexp.last_match, matched_text) end else text.gsub!(@to, reverse_from) end end |
#replace(text) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/extract_i18n/html_extractor/two_way_regexp.rb', line 11 def replace(text) if block_given? text.gsub(@from) do |matched_text| yield(to_as_format, Regexp.last_match, matched_text) end else text.gsub(@from, reverse_to) end end |
#replace!(text) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/extract_i18n/html_extractor/two_way_regexp.rb', line 21 def replace!(text) if block_given? text.gsub!(@from) do |matched_text| yield(to_as_format, Regexp.last_match, matched_text) end else text.gsub!(@from, reverse_to) end end |