Class: Ykutils::StructuredTextForAccount
- Inherits:
-
StructuredText
- Object
- StructuredText
- Ykutils::StructuredTextForAccount
- Defined in:
- lib/ykutils/stext.rb
Constant Summary
Constants included from NKFUTIL
Instance Attribute Summary collapse
-
#main_domain_ary ⇒ Object
readonly
Returns the value of attribute main_domain_ary.
-
#main_domain_hash ⇒ Object
readonly
Returns the value of attribute main_domain_hash.
-
#main_host_ary ⇒ Object
readonly
Returns the value of attribute main_host_ary.
-
#main_host_hash ⇒ Object
readonly
Returns the value of attribute main_host_hash.
-
#main_host_item_ary ⇒ Object
readonly
Returns the value of attribute main_host_item_ary.
-
#main_sep_ary ⇒ Object
readonly
Returns the value of attribute main_sep_ary.
-
#main_sep_hash ⇒ Object
readonly
Returns the value of attribute main_sep_hash.
Attributes inherited from StructuredText
#item_ary, #main_ary, #main_hash
Instance Method Summary collapse
- #analyze(line_ary, fname = nil) ⇒ Object
- #analyze_sub(lines) ⇒ Object
- #dump(file = nil) ⇒ Object
- #dump_sub(ary, hash) ⇒ Object
- #dump_sub_for_array(ary, hash) ⇒ Object
-
#initialize ⇒ StructuredTextForAccount
constructor
A new instance of StructuredTextForAccount.
- #sort_by(other) ⇒ Object
- #sort_by_sub(itx, item_hash, item_ary, n_hash, n_ary) ⇒ Object
- #sort_by_sub_for_array(itx, item_hash, n_hash, n_ary) ⇒ Object
Methods inherited from StructuredText
#dump_to_file, #load, #load_analyze
Methods included from DebugUtils
#clear_d, #d, #d_caller, #d_exit, #d_p, #d_pp, #d_puts, #d_puts_no_empty, #debug_utils_init, #error_exit, #puts_current_method, #puts_d, #puts_no_empty, #w1_puts, #w2_puts
Methods included from DataStructOp
#exchange, #make_array, #make_hash, #select_array
Methods included from SpecFileOp
#check_data_complement, #check_data_complement_print_message, #dump_yaml_fileobj, #expand_data, #load_csv_file, #load_csv_file_ex, #load_plain_text_file, #load_yaml_file, #make_data_complement, #open_for_write, #parse_yaml_file, #save_yaml_file, #valid?
Methods included from NKFUTIL
assoc_equal, auto_config_from_inner, auto_config_to_inner, config, convert, get, guess_encoding, #nkf_utf8_file, #puts_sj, #puts_u, set
Constructor Details
#initialize ⇒ StructuredTextForAccount
Returns a new instance of StructuredTextForAccount.
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/ykutils/stext.rb', line 68 def initialize super() @main_host_item_ary = [] @main_sep_ary = [] @main_sep_hash = {} @main_host_ary = [] @main_host_hash = {} @main_domain_ary = [] @main_domain_hash = {} end |
Instance Attribute Details
#main_domain_ary ⇒ Object (readonly)
Returns the value of attribute main_domain_ary.
65 66 67 |
# File 'lib/ykutils/stext.rb', line 65 def main_domain_ary @main_domain_ary end |
#main_domain_hash ⇒ Object (readonly)
Returns the value of attribute main_domain_hash.
65 66 67 |
# File 'lib/ykutils/stext.rb', line 65 def main_domain_hash @main_domain_hash end |
#main_host_ary ⇒ Object (readonly)
Returns the value of attribute main_host_ary.
65 66 67 |
# File 'lib/ykutils/stext.rb', line 65 def main_host_ary @main_host_ary end |
#main_host_hash ⇒ Object (readonly)
Returns the value of attribute main_host_hash.
65 66 67 |
# File 'lib/ykutils/stext.rb', line 65 def main_host_hash @main_host_hash end |
#main_host_item_ary ⇒ Object (readonly)
Returns the value of attribute main_host_item_ary.
65 66 67 |
# File 'lib/ykutils/stext.rb', line 65 def main_host_item_ary @main_host_item_ary end |
#main_sep_ary ⇒ Object (readonly)
Returns the value of attribute main_sep_ary.
65 66 67 |
# File 'lib/ykutils/stext.rb', line 65 def main_sep_ary @main_sep_ary end |
#main_sep_hash ⇒ Object (readonly)
Returns the value of attribute main_sep_hash.
65 66 67 |
# File 'lib/ykutils/stext.rb', line 65 def main_sep_hash @main_sep_hash end |
Instance Method Details
#analyze(line_ary, fname = nil) ⇒ Object
82 83 84 85 86 87 |
# File 'lib/ykutils/stext.rb', line 82 def analyze(line_ary, fname = nil) lines = AccountLines.new(line_ary) lines.output_f(fname) analyze_sub(lines) end |
#analyze_sub(lines) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/ykutils/stext.rb', line 89 def analyze_sub(lines) host = StructuredTextForAccountOneLayerHost.new domain = StructuredTextForAccountOneLayerDomain.new while (line = lines.get_line) case line["STATUS"] when AccountLines::HOST_ACCOUNT_START, AccountLines::HOST_ACCOUNT, AccountLines::HOST_ACCOUNT_END key, value = line["CONTENT"].split(":") if line["CONTENT"] key&.strip! value&.strip! host.analyze(line["STATUS"], line, key, value, @main_host_ary, @main_host_hash) when AccountLines::DOMAIN_ACCOUNT_START, AccountLines::DOMAIN_ACCOUNT, AccountLines::DOMAIN_ACCOUNT_END key, value = line["CONTENT"].split(":") if line["CONTENT"] key&.strip! value&.strip! domain.analyze(line["STATUS"], line, key, value, @main_domain_ary, @main_domain_hash) when AccountLines::SEPARATOR key, value = line["CONTENT"].split(":") if line["CONTENT"] @main_sep_ary << key @main_sep_hash[key] = { "TITLE" => key } else puts("Error") puts(line["CONTENT"]) end end @main_host_item_ary |= host.item_ary end |
#dump(file = nil) ⇒ Object
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/ykutils/stext.rb', line 185 def dump(file = nil) dump_ary = [] dump_ary += dump_sub(@main_sep_ary, @main_sep_hash) dump_ary += dump_sub(@main_host_ary, @main_host_hash) dump_ary += dump_sub_for_array(@main_domain_ary, @main_domain_hash) str = dump_ary.join("\n") if file begin file.write(str) file.write("\n") rescue StandardError => e pp e pp e.backtrace @valid = false end end str end |
#dump_sub(ary, hash) ⇒ Object
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/ykutils/stext.rb', line 206 def dump_sub(ary, hash) dump_ary = [] ary.each do |it| h = hash[it] next unless h item_ary = h["META"] title = h["TITLE"] item_hash = h["CONTENT"] dump_ary << title next unless item_ary item_ary.each do |subit| dump_ary << item_hash[subit] if item_hash[subit] end end dump_ary end |
#dump_sub_for_array(ary, hash) ⇒ Object
226 227 228 229 230 231 232 |
# File 'lib/ykutils/stext.rb', line 226 def dump_sub_for_array(ary, hash) dump_ary = [] ary.each do |it| dump_ary += hash[it]["CONTENT"] end dump_ary end |
#sort_by(other) ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/ykutils/stext.rb', line 118 def sort_by(other) diff_main_host_ary = @main_host_ary - other.main_host_ary diff_main_domain_ary = @main_domain_ary - other.main_domain_ary n_main_sep_hash = {} n_main_host_ary = [] n_main_host_hash = {} n_main_domain_ary = [] n_main_domain_hash = {} unless other.main_sep_ary.empty? @main_sep_ary |= other.main_sep_ary @main_sep_hash |= n_main_sep_hash end main_host_item_ary = other.main_host_item_ary | @main_host_item_ary other.main_host_ary.each do |it| sort_by_sub(it, @main_host_hash, main_host_item_ary, n_main_host_hash, n_main_host_ary) end diff_main_host_ary.each do |it| sort_by_sub(it, @main_host_hash, main_host_item_ary, n_main_host_hash, n_main_host_ary) end other.main_domain_ary.each do |it| sort_by_sub_for_array(it, @main_domain_hash, n_main_domain_hash, n_main_domain_ary) end diff_main_domain_ary.each do |it| sort_by_sub_for_array(it, @main_domain_hash, n_main_domain_hash, n_main_domain_ary) end @main_host_ary = n_main_host_ary @main_host_hash = n_main_host_hash @main_domain_ary = n_main_domain_ary @main_domain_hash = n_main_domain_hash end |
#sort_by_sub(itx, item_hash, item_ary, n_hash, n_ary) ⇒ Object
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/ykutils/stext.rb', line 156 def sort_by_sub(itx, item_hash, item_ary, n_hash, n_ary) h = item_hash[itx] return unless h n_ary << itx title = h["TITLE"] hash = h["CONTENT"] ary = [] if hash item_ary.each do |ai| v = hash[ai] ary << ai if v end end n_hash[itx] = { "TITLE" => title, "META" => ary, "CONTENT" => hash } end |
#sort_by_sub_for_array(itx, item_hash, n_hash, n_ary) ⇒ Object
173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/ykutils/stext.rb', line 173 def sort_by_sub_for_array(itx, item_hash, n_hash, n_ary) h = item_hash[itx] return unless h n_ary << itx title = h["TITLE"] ary = h["META"] hash = h["CONTENT"] n_hash[it] = { "TITLE" => title, "META" => ary, "CONTENT" => hash } end |