class ExportStrings::BySexp

文字列展開は含めない

Public Class Methods

execute(rb_text) click to toggle source
# File lib/export_strings/by_sexp.rb, line 7
def execute(rb_text)
  str_content_nodes = recursively_push_for_str_content_nodes Ripper.sexp(rb_text), []
  content_nodes2str_ary str_content_nodes
end

Private Class Methods

content_nodes2str_ary(nodes) click to toggle source

nodesをstringsに変換して返す

# File lib/export_strings/by_sexp.rb, line 27
def content_nodes2str_ary(nodes)
  nodes.map { |node| str_content_node2str node, '' }
end
recursively_push_for_str_content_nodes(tree, nodes) click to toggle source

再帰的にstring_literal nodeを集めてくる

# File lib/export_strings/by_sexp.rb, line 15
def recursively_push_for_str_content_nodes(tree, nodes)
  tree.each do |node|
    if node.class == Array && node[0] == :string_content
      nodes << node
    elsif node.class == Array
      recursively_push_for_str_content_nodes(node, nodes)
    end
  end
  nodes
end
str_content_node2str(string_content_node, str) click to toggle source

各nodeをstringに変換する

# File lib/export_strings/by_sexp.rb, line 32
def str_content_node2str(string_content_node, str)
  string_content_node.each do |leaf|
    if leaf.class == Array && leaf[0] == :@tstring_content
      # 通常のstringが格納される時
      str << leaf[1]
    elsif leaf.class == Array
      str_content_node2str(leaf, str)
    end
  end
  str
end