Sha256: 02026839b19c84a1416a6e72895b2e36923cebc7f59ce2b40b814c53003d5786

Contents?: true

Size: 1.22 KB

Versions: 2

Compression:

Stored size: 1.22 KB

Contents

#!/usr/bin/ruby
require 'optparse'
require 'genkaio'
#interactive mode
if $*==[]
 Genkaio.interactive
end

# paramaters
hiragana=[nil,nil]
length=0
line_number=10

# parsing options
opt = OptionParser.new

opt.on('-h', '--help') {
 Genkaio.help(true)
}
opt.on('-l VALUE', '--line-number VALUE', Integer) {|v|
 if v.to_i>=0
  line_number=v.to_i
 else
  raise ArgumentError, "line-number should be >=0"
 end
}
opt.on('-e VALUE', '-f VALUE','--last VALUE', String) {|v|
 if v=~/^[ァ-ンー]$/
  hiragana[1]=v[0]
 else
  raise ArgumentError, "last hiragana should be one"
 end
}
opt.on('-v'){
 puts Genkaio.version
 exit(true)
}

# change full-width args into half-width and hiragana into katakana

args=$* # $* is readonly-variable

args.map!{|_|_.tr("0-9A-Za-zーぁ-ん ","0-9A-Za-z-ァ-ン ")}
args.map!(&:split).flatten!
opt.parse!(args)

# dealing with different spacing
if args.size==1 && args[0][0]=~/^[ァ-ン]$/ && args[0][1,100].to_i>1
 hiragana[0]=args[0][0]
 length=args[0][1,100].to_i-2
elsif args.size==2 && args[0]=~/^[ァ-ン]$/ && args[1].to_i>1
 hiragana[0]=args[0]
 length=args[1].to_i-2
else
  raise ArgumentError, ""
end

result=Genkaio.search(
Genkaio.getpath,
hiragana,
length,
line_number)

puts result

exit(true)

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
genkaio-0.0.2 bin/genkaio
genkaio-0.0.1 bin/genkaio