lib/ykutils/specfileop.rb in ykutils-0.1.7 vs lib/ykutils/specfileop.rb in ykutils-0.1.8

- old
+ new

@@ -1,8 +1,7 @@ # -*- coding utf-8 -*- -require "pp" require "yaml" require "csv" require "ykutils/treemanagera" if RUBY_VERSION >= "1.8.7" require "ykutils/nkfutil19" @@ -61,11 +60,11 @@ @data end def parse_yaml_file(fname) begin - @data = YAML.parse(File.read(fname)) + @data = YAML.parse_file(fname) rescue StandardError => e pp e pp e.backtrace @valid = false end @@ -80,24 +79,23 @@ next unless v v.scan(re).flatten.each do |it| if it tm.add(it, k) - tm.addTag(k, it) + tm.tag(k, it) else tm.add(nil, k) end end end tm.tsort.reverse.each do |k| next unless data[k] - tag = tm.getTag(k) + tag = tm.tag(k) next unless tag - i = 0 tag.each do |it| ntag = Regexp.new(separator + it + separator) data[k] = data[k].sub(ntag, data[it]) if data[it] end end @@ -105,27 +103,27 @@ data.each do |k, v| next unless v ary = v.scan(re).flatten i = 0 - if ary and ary.size > 0 + if ary && !ary.empty? except_ary.each do |it| i += 1 unless ary.index(it) end end - if i > 0 + if i.positive? puts "#{k} fails to exapnd data. value is #{v}" @valid = false end end data end def make_data_complement(item_ary, data, common) item_ary.each do |it| - data[it] = common[it] unless data[it] and data[it].strip != "" + data[it] = common[it] unless data[it] && (data[it].strip != "") end end def check_data_complement(item_ary, _data) mes_ary = [] @@ -180,12 +178,12 @@ def load_plain_text_file(fname) ary = [] begin ary0 = File.readlines(fname) - senc = NKFUTIL.auto_config_to_inner(ary0.join) + NKFUTIL.auto_config_to_inner(ary0.join) - ary = ary0.select { |x| !x.nil? }.collect do |x| + ary = ary0.compact.collect do |x| if x.nil? "" else NKFUTIL.convert(x) end