class ExtractI18n::HTMLExtractor::TwoWayRegexp

Attributes

from[R]
to[R]

Public Class Methods

new(from, to) click to toggle source
# File lib/extract_i18n/html_extractor/two_way_regexp.rb, line 6
def initialize(from, to)
  @from = from
  @to = to
end

Public Instance Methods

inverse_replace(text) { |from_as_format, last_match, matched_text| ... } click to toggle source
# 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) { |from_as_format, last_match, matched_text| ... } click to toggle source
# 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) { |to_as_format, last_match, matched_text| ... } click to toggle source
# 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) { |to_as_format, last_match, matched_text| ... } click to toggle source
# 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

Private Instance Methods

from_as_format() click to toggle source
# File lib/extract_i18n/html_extractor/two_way_regexp.rb, line 57
def from_as_format
  @from_as_format ||= @from.source.gsub('%', '%%').gsub!(/\(\?<([a-z_]+)>.*\)/, '%{\1}')
end
reverse_from() click to toggle source
# File lib/extract_i18n/html_extractor/two_way_regexp.rb, line 61
def reverse_from
  @reverse_from ||= @from.source.gsub(/\(\?<([a-z_]+)>.*\)/, '\k{\1}')
end
reverse_to() click to toggle source
# File lib/extract_i18n/html_extractor/two_way_regexp.rb, line 65
def reverse_to
  @reverse_to ||= @to.source.gsub(/\(\?<([a-z_]+)>.*\)/, '\k{\1}')
end
to_as_format() click to toggle source
# File lib/extract_i18n/html_extractor/two_way_regexp.rb, line 53
def to_as_format
  @to_as_format ||= @to.source.gsub('%', '%%').gsub!(/\(\?<([a-z_]+)>.*\)/, '%{\1}')
end