Class: RubyJS::CodeJoin
- Inherits:
-
Object
- Object
- RubyJS::CodeJoin
- Defined in:
- lib/ruby_js/code_join.rb
Constant Summary collapse
- FILE_N =
"FILE_N"- TEST_N =
"test.rjs"- FILE_HN =
".codejoin"
Instance Attribute Summary collapse
-
#json_cj ⇒ Object
readonly
Returns the value of attribute json_cj.
Instance Method Summary collapse
- #add_file(path_f) ⇒ Object
- #change_extend_class_position(last_class, fe_arr_uniq) ⇒ Object
- #check_last_extend_class(fe_arr) ⇒ Object
- #extends_pos_class(hash) ⇒ Object
- #get_ignore_r ⇒ Object
- #get_pos_class ⇒ Object
-
#initialize(path_s) ⇒ CodeJoin
constructor
A new instance of CodeJoin.
- #to_s ⇒ Object
Constructor Details
#initialize(path_s) ⇒ CodeJoin
Returns a new instance of CodeJoin.
13 14 15 16 17 18 19 |
# File 'lib/ruby_js/code_join.rb', line 13 def initialize path_s @files = [] @json_cj = JsonParser.new File.join(path_s, FILE_HN) @json_cj.on :name, "project" @json_cj.on :ignore, ["#{FILE_N}_.*.rjs", TEST_N, "main.rjs"] end |
Instance Attribute Details
#json_cj ⇒ Object (readonly)
Returns the value of attribute json_cj.
11 12 13 |
# File 'lib/ruby_js/code_join.rb', line 11 def json_cj @json_cj end |
Instance Method Details
#add_file(path_f) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/ruby_js/code_join.rb', line 21 def add_file path_f content = File.open(path_f).read i_c = content.index /class/ i_n = content.index(/\n/, i_c) if i_c @files << FileS.new(path_f, content, [i_c, i_n]) end |
#change_extend_class_position(last_class, fe_arr_uniq) ⇒ Object
107 108 109 110 111 112 113 |
# File 'lib/ruby_js/code_join.rb', line 107 def change_extend_class_position last_class, fe_arr_uniq last_class.each do |c| i_c = fe_arr_uniq.delete c fe_arr_uniq.push c end return fe_arr_uniq end |
#check_last_extend_class(fe_arr) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/ruby_js/code_join.rb', line 115 def check_last_extend_class fe_arr last_class = [] fe_arr.each do |cs| unless last_class.empty? last_class.each do |c| is_exist = cs.find_index(c) if is_exist last_class.delete(c) end end end if cs.length == 1 last_class << cs[0] end end return last_class end |
#extends_pos_class(hash) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/ruby_js/code_join.rb', line 68 def extends_pos_class hash fe_arr = [] # Extend class fa_arr = [] # No extend class hash.each do |c, e| if e arr_c = [c, e] def e_loop hash, key k = hash.dig(key) if k yield k e_loop(hash, k) do |kk| yield kk end end end e_loop(hash, e) do |k| arr_c << k end arr_c.pop fe_arr << arr_c.reverse else fa_arr << c end end last_class = check_last_extend_class(fe_arr) fe_arr_ue = [] fe_arr.each do |cs| cs.each do |c| fe_arr_ue << c end end fe_arr_uniq = change_extend_class_position(last_class, fe_arr_ue.uniq) return fa_arr.clone.concat(fe_arr_uniq) end |
#get_ignore_r ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/ruby_js/code_join.rb', line 28 def get_ignore_r result = "" @json_cj.parse(:ignore).each do |i| result << i.sub(/#{FILE_N}/, @json_cj.parse(:name).downcase.gsub(' ', '_')).concat("$|") end return result.sub(/\|$/, '') end |
#get_pos_class ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/ruby_js/code_join.rb', line 36 def get_pos_class files_ch = {} files_nc = [] @files.each do |f| if f.class_rid[0] r_class = f.content[f.class_rid[0], f.class_rid[1] - f.class_rid[0]] r_class_s = r_class.split(' ') _class = r_class_s[1] _super = r_class_s[3] files_ch[_class] = _super else files_nc << f end end files_c = [] extends_pos_class(files_ch).each do |c| @files.each do |f| if f.class_rid[0] r_class = f.content[f.class_rid[0], f.class_rid[1] - f.class_rid[0]] if r_class.index("class #{c}") files_c << f break end end end end return files_c + files_nc end |
#to_s ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/ruby_js/code_join.rb', line 134 def to_s result = "" # " * Module Description" + # " *" + # " * @version #{}" + # " * @date #{}" + # " * @author #{}" + # " * @remarks #{}" + # " * @github #{}" + # " */" get_pos_class.each do |f_s| content_e = f_s.content.gsub(/import.*\n/, '').gsub('export ', '').gsub('default ', '') content_en = content_e[content_e.length - 1] == "\n" ? content_e : content_e.concat("\n") result << content_en end return result end |