Class: CodeStock::Cdstk
- Inherits:
-
Object
- Object
- CodeStock::Cdstk
- Defined in:
- lib/cdstk/cdstk.rb
Constant Summary collapse
- DB_FILE_PATH =
'db/grendb.db'
- DEFAULT_TOKENIZER =
記号・アルファベット・数字もバイグラムでトークナイズする。
"TokenBigramSplitSymbolAlphaDigit"
Instance Method Summary collapse
- #add(*content) ⇒ Object
- #dump ⇒ Object
- #init ⇒ Object
-
#initialize(io = $stdout, db_dir = ".") ⇒ Cdstk
constructor
A new instance of Cdstk.
- #list ⇒ Object
- #rebuild ⇒ Object
- #remove(*content) ⇒ Object
- #update ⇒ Object
- #update_dir(dir) ⇒ Object
Constructor Details
#initialize(io = $stdout, db_dir = ".") ⇒ Cdstk
Returns a new instance of Cdstk.
24 25 26 27 28 29 30 31 |
# File 'lib/cdstk/cdstk.rb', line 24 def initialize(io = $stdout, db_dir = ".") @db_dir = db_dir @out = io @file_count = 0 @add_count = 0 @update_count = 0 @start_time = Time.now end |
Instance Method Details
#add(*content) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/cdstk/cdstk.rb', line 60 def add(*content) # 絶対パスに変換 content.map!{|v|File.(v)} # YAML更新 yaml = yaml_load yaml.add(*content) yaml.save # 部分アップデート db_open(db_file) content.each do |dir| update_dir(dir) end end |
#dump ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/cdstk/cdstk.rb', line 98 def dump db_open(db_file) documents = Groonga::Context.default["documents"] records = documents.select records.each do |record| @out.puts record.inspect @out.puts "path : #{record.path}" @out.puts "shortpath : #{record.shortpath}" @out.puts "suffix : #{record.suffix}" @out.puts "timestamp : #{record..strftime('%Y/%m/%d %H:%M:%S')}" @out.puts "content :", record.content ? record.content[0..64] : nil @out.puts end end |
#init ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/cdstk/cdstk.rb', line 33 def init if Dir.entries(@db_dir) == [".", ".."] CdstkYaml.create(@db_dir) @out.puts "create : #{yaml_file}" db_create(db_file) else @out.puts "Can't create Grendb Database (Not empty) in #{@db_dir}" end end |
#list ⇒ Object
88 89 90 |
# File 'lib/cdstk/cdstk.rb', line 88 def list @out.puts yaml_load.list end |
#rebuild ⇒ Object
92 93 94 95 96 |
# File 'lib/cdstk/cdstk.rb', line 92 def rebuild db_delete(db_file) db_create(db_file) update end |
#remove(*content) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/cdstk/cdstk.rb', line 76 def remove(*content) # 絶対パスに変換 content.map!{|v|File.(v)} # YAML更新 yaml = yaml_load yaml.remove(*content) yaml.save # @todo 削除したコンテンツをインデックスから削除 end |
#update ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/cdstk/cdstk.rb', line 43 def update print_result do yaml = yaml_load db_open(db_file) yaml.contents.each do |content| update_dir_in(content["directory"]) end end end |
#update_dir(dir) ⇒ Object
54 55 56 57 58 |
# File 'lib/cdstk/cdstk.rb', line 54 def update_dir(dir) print_result do update_dir_in(dir) end end |