Module: Genkaio

Defined in:
lib/genkaio.rb,
lib/genkaio/version.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

VERSION =
"0.0.2"

Class Method Summary collapse

Class Method Details

.getpathObject



10
11
12
# File 'lib/genkaio.rb', line 10

def self.getpath
 return Dir.glob("#{__dir__}/dic/dicdata*").sort[-1]
end

.help(boo) ⇒ Object

ヘルプ



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/genkaio.rb', line 39

def self.help(boo)
STDERR.puts <<-'USAGE'
 COMMAND:
            genkaio - Show candidate answers for "genkai-shiritori"
 USAGE:
            genkaio [first hiragana] [length]
                    [-l, --line-number(default:10)]
                    [-e, -f, --last(default:nil)]
            genkaio [--help]
            genkaio [-h]
 EXAMPLE:
            genkaio あ8
            genkaio あ 10 -l5 -e る
 USAGE
 exit(boo)
end

.interactiveObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/genkaio.rb', line 14

def self.interactive
if RUBY_PLATFORM =~ /linux/
 count=0
 puts <<-'EOS'
 == INTERACTIVE  MODE ==
 == Ctrl+C,exit->quit ==
 EOS
 loop{
  begin
   count+=1
   print("genkaio:#{"%03d"%count}>>")
   i=gets.chomp
   exit(true) if i=="exit"
   puts "=================="
   puts(`[ -n "#{i}" ]&&genkaio #{i}`)
   puts "=================="
  rescue Interrupt
   puts
   exit(true)
  end
  }
 end
end

.search(dicpath, hiragana, length, line_number = 10) ⇒ Object

ファイルを開いて検索



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/genkaio.rb', line 58

def self.search(dicpath, hiragana, length, line_number=10)

 File.open(dicpath, "r"){|f|

  hitdata=f.read.split("\n")
  if hiragana[1].nil?
   hitdata=hitdata.grep(/ #{hiragana[0]}.{#{length}}[^ン]$/)
  .shuffle![0,line_number].map!{|_|_.tr('ァ-ン','ぁ-ん')}
  else
   hitdata=hitdata.grep(/ #{hiragana[0]}.{#{length}}[#{hiragana[1]}]$/)
  .shuffle![0,line_number].map!{|_|_.tr('ァ-ン','ぁ-ん')}
  end
  return hitdata
 }
end

.versionObject



6
7
8
# File 'lib/genkaio.rb', line 6

def self.version
 return Genkaio::VERSION
end