#! /usr/bin/env ruby # coding: utf-8 # split a line to lines. require "pp" require "optparse" require "rubygems" require "tefil" # option analysis options = { #:period => true, :separator => ".", :except => "" } op = OptionParser.new #op.banner = [ # "Usage: #{File.basename("#{__FILE__}")} [options] [files]", #].join("\n") op.on("-o" , "--overwrite" , "Overwrite."){ options[:overwrite] = true} op.on("-t str" , "--separator=str" , "Target strings. Default value is '.'"){ |v| options[:separator] = v} op.on("-e str" , "--except=str" , "Except strings."){ |v| options[:except] = v} op.on("-s" , "--space" , "Add space to separators."){ options[:space] = true} op.on("-S" , "--strip" , "Strip extra space at head and tail of line."){ options[:strip] = true} op.parse!(ARGV) options[:overwrite] ||= false #EXCEPT_WORDS = ["Fig.", "FIG."] separators = [] separators += options[:separator].split(" ") separators << ' ' if options[:space] separators.uniq! indent_mode = :no indent_mode = :strip if options[:strip] #pp separators; exit is = Tefil::LineSplitter.new(separators: separators, except_words: options[:except].split(" "), indent_mode: indent_mode, options: options) #pp is; exit is.filter(ARGV)