Class: Ykutils::StructuredTextForSimple
- Inherits:
-
StructuredText
- Object
- StructuredText
- Ykutils::StructuredTextForSimple
- Defined in:
- lib/ykutils/stext.rb
Defined Under Namespace
Classes: Item
Constant Summary
Constants included from NKFUTIL
Instance Attribute Summary
Attributes inherited from StructuredText
#item_ary, #main_ary, #main_hash
Instance Method Summary collapse
- #analyze(line_ary, _subfname = nil) ⇒ Object
- #event ⇒ Object
- #get_next_state(state, event) ⇒ Object
-
#initialize ⇒ StructuredTextForSimple
constructor
A new instance of StructuredTextForSimple.
- #make_next_state_table ⇒ Object
- #procx ⇒ 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 ⇒ StructuredTextForSimple
Returns a new instance of StructuredTextForSimple.
304 305 306 307 |
# File 'lib/ykutils/stext.rb', line 304 def initialize super() @item_ary = {} end |
Instance Method Details
#analyze(line_ary, _subfname = nil) ⇒ Object
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 |
# File 'lib/ykutils/stext.rb', line 365 def analyze(line_ary, _subfname = nil) @line_ary = line_ary make_next_state_table # :NONE # :ITEM # :END # :BAD # :EMPTY_LINE # :TITLE_LINE # :EMPTY_TITLE_LINE # :NON_EMPTY_LINE state = :NONE event = get_event @item_ary = [] item = nil while (state != :BAD) && (event[0] != :EOF) case state when :NONE, :ITEM procx else case event[0] when :EMPTY_LINE, :TITLE_LINE, :EMPTY_TITLE_LINE, :NON_EMPTY_LINE item.add(event[1]) end end state = get_next_state(state, event[0]) event = get_event end @item_ary end |
#event ⇒ Object
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 |
# File 'lib/ykutils/stext.rb', line 309 def event value = nil line = @line_ary.shift if line content = line.strip if content.empty? ret = :EMPTY_LINE value = "" elsif content =~ /^-(.*)/ title = Regexp.last_match(1) if title.empty? ret = :EMPTY_TITLE_LINE value = "" else ret = :TITLE_LINE value = title end else ret = :NON_EMPTY_LINE value = content end else ret = :EOF end [ret, value] end |
#get_next_state(state, event) ⇒ Object
357 358 359 360 361 362 363 |
# File 'lib/ykutils/stext.rb', line 357 def get_next_state(state, event) if state == :BAD :BAD else @next_state[state][event] end end |
#make_next_state_table ⇒ Object
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 |
# File 'lib/ykutils/stext.rb', line 338 def make_next_state_table @next_state = {} @next_state[:NONE] = {} @next_state[:NONE][:EMPTY_LINE] = :NONE @next_state[:NONE][:TITLE_LINE] = :ITEM @next_state[:NONE][:EMPTY_TITLE_LINE] = :END @next_state[:NONE][:NON_EMPTY_LINE] = :BAD @next_state[:ITEM] = {} @next_state[:ITEM][:EMPTY_LINE] = :ITEM @next_state[:ITEM][:TITLE_LINE] = :ITEM @next_state[:ITEM][:EMPTY_TITLE_LINE] = :END @next_state[:ITEM][:NON_EMPTY_LINE] = :ITEM @next_state[:END] = {} @next_state[:END][:EMPTY_LINE] = :END @next_state[:END][:TITLE_LINE] = :BAD @next_state[:END][:EMPTY_TITLE_LINE] = :BAD @next_state[:END][:NON_EMPTY_LINE] = :END end |