Class: Avm::EacRubyBase1::Sources::NamespaceReplacer
- Inherits:
-
Object
- Object
- Avm::EacRubyBase1::Sources::NamespaceReplacer
- Defined in:
- lib/avm/eac_ruby_base1/sources/namespace_replacer.rb
Constant Summary collapse
- TAB =
' '
Instance Method Summary collapse
- #concat_regex(regexes) ⇒ Object
- #from_close ⇒ Object
- #from_open ⇒ Object
- #from_result ⇒ Object
- #to_close ⇒ String
- #to_open ⇒ String
- #to_result ⇒ Object
Instance Method Details
#concat_regex(regexes) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/avm/eac_ruby_base1/sources/namespace_replacer.rb', line 11 def concat_regex(regexes) r = regexes.first regexes[1..].each do |x| r = ::Regexp.new(r.source + x.source) end r end |
#from_close ⇒ Object
28 29 30 |
# File 'lib/avm/eac_ruby_base1/sources/namespace_replacer.rb', line 28 def from_close concat_regex(from.split('::').count.times.map { / *end *\n/m }) end |
#from_open ⇒ Object
23 24 25 26 |
# File 'lib/avm/eac_ruby_base1/sources/namespace_replacer.rb', line 23 def from_open concat_regex(from.split('::') .map { |v| / *(?:class|module) +#{::Regexp.quote(v)} *\n/m }) end |
#from_result ⇒ Object
19 20 21 |
# File 'lib/avm/eac_ruby_base1/sources/namespace_replacer.rb', line 19 def from_result /\n#{from_open.source}(.+)#{from_close.source}/m end |
#to_close ⇒ String
46 47 48 49 50 51 52 53 54 |
# File 'lib/avm/eac_ruby_base1/sources/namespace_replacer.rb', line 46 def to_close parts = to.split('::') s = '' parts.each_with_index do |_part, index| tabc = (parts.count - 1 - index) s += "#{tab(tabc)}end\n" end s end |
#to_open ⇒ String
37 38 39 40 41 42 43 |
# File 'lib/avm/eac_ruby_base1/sources/namespace_replacer.rb', line 37 def to_open s = '' to.split('::').each_with_index do |part, index| s += tab(index) + "module #{part}\n" end s end |
#to_result ⇒ Object
32 33 34 |
# File 'lib/avm/eac_ruby_base1/sources/namespace_replacer.rb', line 32 def to_result "\n\n#{to_open}\\1#{to_close}" end |