logaling-command 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,11 +4,10 @@ require 'thor'
4
4
  require "logaling/glossary"
5
5
 
6
6
  class Logaling::Command < Thor
7
- VERSION = "0.0.4"
7
+ VERSION = "0.0.5"
8
8
  LOGALING_CONFIG = '.logaling'
9
9
 
10
- map '-c' => :create,
11
- '-a' => :add,
10
+ map '-a' => :add,
12
11
  '-d' => :delete,
13
12
  '-u' => :update,
14
13
  '-l' => :lookup,
@@ -41,80 +40,79 @@ class Logaling::Command < Thor
41
40
  desc 'register', 'Register .logaling'
42
41
  def register
43
42
  logaling_path = find_dotfile
44
- if logaling_path
45
- FileUtils.mkdir_p(logaling_projects_path) unless File.exist?(logaling_projects_path)
46
-
47
- config = load_config
48
- symlink_path = File.join(logaling_projects_path, config["glossary"])
49
- unless File.exists?(symlink_path)
50
- FileUtils.ln_s(logaling_path, symlink_path)
51
- say "Your project is now registered to #{symlink_path}."
52
- else
53
- say "#{options["glossary"]} is already registered."
54
- end
43
+ FileUtils.mkdir_p(logaling_projects_path) unless File.exist?(logaling_projects_path)
44
+
45
+ config = load_config
46
+ symlink_path = File.join(logaling_projects_path, config["glossary"])
47
+ unless File.exists?(symlink_path)
48
+ FileUtils.ln_s(logaling_path, symlink_path)
49
+ say "#{config['glossary']} is now registered to logaling."
55
50
  else
56
- say "Try 'loga new' first."
51
+ say "#{config['glossary']} is already registered."
57
52
  end
53
+ rescue Logaling::CommandFailed => e
54
+ say e.message
55
+ say "Try 'loga new' first."
58
56
  end
59
57
 
60
58
  desc 'unregister', 'Unregister .logaling'
61
59
  def unregister
62
60
  logaling_path = find_dotfile
63
- if logaling_path
64
- config = load_config
65
- symlink_path = File.join(logaling_projects_path, config["glossary"])
66
- if File.exists?(symlink_path)
67
- FileUtils.remove_entry_secure(symlink_path, true)
68
- say "Your project is now unregistered."
69
- else
70
- say ".logaling is not yet registered."
71
- end
61
+ config = load_config
62
+ symlink_path = File.join(logaling_projects_path, config["glossary"])
63
+ if File.exists?(symlink_path)
64
+ FileUtils.remove_entry_secure(symlink_path, true)
65
+ say "#{config['glossary']} is now unregistered."
72
66
  else
73
- say ".logaling can't be found."
67
+ say "#{config['glossary']} is not yet registered."
74
68
  end
75
- end
76
-
77
- desc 'create', 'Create glossary.'
78
- def create
79
- glossary.create
80
69
  rescue Logaling::CommandFailed => e
81
- error(e.message)
70
+ say e.message
82
71
  end
83
72
 
84
73
  desc 'add [SOURCE TERM] [TARGET TERM] [NOTE(optional)]', 'Add term to glossary.'
85
74
  def add(source_term, target_term, note='')
86
75
  glossary.add(source_term, target_term, note)
87
76
  rescue Logaling::CommandFailed, Logaling::TermError => e
88
- error(e.message)
77
+ say e.message
89
78
  end
90
79
 
91
80
  desc 'delete [SOURCE TERM] [TARGET TERM]', 'Delete term.'
92
81
  def delete(source_term, target_term)
93
82
  glossary.delete(source_term, target_term)
94
83
  rescue Logaling::CommandFailed, Logaling::TermError => e
95
- error(e.message)
84
+ say e.message
85
+ rescue Logaling::GlossaryNotFound => e
86
+ say "Try 'loga new or register' first."
96
87
  end
97
88
 
98
89
  desc 'update [SOURCE TERM] [TARGET TERM] [NEW TARGET TERM], [NOTE(optional)]', 'Update term.'
99
90
  def update(source_term, target_term, new_target_term, note='')
100
91
  glossary.update(source_term, target_term, new_target_term, note)
101
92
  rescue Logaling::CommandFailed, Logaling::TermError => e
102
- error(e.message)
93
+ say e.message
94
+ rescue Logaling::GlossaryNotFound => e
95
+ say "Try 'loga new or register' first."
103
96
  end
104
97
 
105
98
  desc 'lookup [TERM]', 'Lookup terms.'
106
99
  def lookup(source_term)
107
- index
108
- glossary.lookup(source_term)
109
- rescue Logaling::CommandFailed, Logaling::TermError => e
110
- error(e.message)
111
- end
112
-
113
- desc 'index', 'Index glossaries to groonga DB.'
114
- def index
115
100
  glossary.index
101
+ terms = glossary.lookup(source_term)
102
+
103
+ puts "\nlookup word : #{source_term}"
104
+ unless terms.empty?
105
+ terms.each do |term|
106
+ puts "\n #{term[:source_term]}\n"
107
+ puts " #{term[:target_term]}\n"
108
+ puts " note:#{term[:note]}"
109
+ puts " glossary:#{term[:name]}"
110
+ end
111
+ else
112
+ "source-term <#{source_term}> not found"
113
+ end
116
114
  rescue Logaling::CommandFailed, Logaling::TermError => e
117
- error(e.message)
115
+ say e.message
118
116
  end
119
117
 
120
118
  private
@@ -156,13 +154,19 @@ class Logaling::Command < Thor
156
154
 
157
155
  def find_dotfile
158
156
  dir = Dir.pwd
157
+ searched_path = []
159
158
  while(dir) do
160
159
  path = File.join(dir, '.logaling')
161
160
  if File.exist?(path)
162
161
  return path
163
- break
162
+ else
163
+ if dir != "/"
164
+ searched_path << dir
165
+ dir = File.dirname(dir)
166
+ else
167
+ raise(Logaling::CommandFailed, "Can't found .logaling in #{searched_path}")
168
+ end
164
169
  end
165
- dir = (dir != "/") ? File.dirname(dir) : nil
166
170
  end
167
171
  end
168
172
  end
@@ -18,98 +18,117 @@ module Logaling
18
18
  @target_language = target_language
19
19
  end
20
20
 
21
- def create
22
- check_glossary_unexists
23
-
24
- dirname = File::dirname(@path)
25
- FileUtils.mkdir_p(dirname)
26
- FileUtils.touch(@path)
27
- end
28
-
29
21
  def add(source_term, target_term, note)
30
- check_glossary_exists
22
+ FileUtils.touch(@path) unless File.exists?(@path)
31
23
 
32
24
  if bilingual_pair_exists?(source_term, target_term)
33
- raise TermError, "[#{source_term}] [#{target_term}] pair already exists"
25
+ raise TermError, "term '#{source_term}: #{target_term}' already exists in '#{@glossary}'"
34
26
  end
35
27
 
36
- glossary = load_glossary_yml
28
+ glossary = load_glossary_yml(@path)
37
29
  glossary << build_term(source_term, target_term, note)
38
30
 
39
31
  dump_glossary(glossary)
40
32
  end
41
33
 
42
34
  def update(source_term, target_term, new_target_term, note)
43
- check_glossary_exists
35
+ raise GlossaryNotFound unless File.exists?(@path)
44
36
 
45
37
  if bilingual_pair_exists?(source_term, new_target_term)
46
- raise TermError, "[#{source_term}] [#{new_target_term}] pair already exists"
38
+ raise TermError, "term '#{source_term}: #{target_term}' already exists in '#{@glossary}'"
47
39
  end
48
40
 
49
- glossary = load_glossary_yml
41
+ glossary = load_glossary_yml(@path)
50
42
  target_index = find_term_index(glossary, source_term, target_term)
51
43
  if target_index
52
44
  glossary[target_index] = rebuild_term(glossary[target_index], source_term, new_target_term, note)
53
45
  dump_glossary(glossary)
54
46
  else
55
- raise TermError, "source_term:#{source_term} target_term:#{target_term} not found in glossary #{@path}"
47
+ raise TermError, "Can't found term '#{source_term}: #{target_term}' in '#{@glossary}'"
56
48
  end
57
49
  end
58
50
 
59
51
  def delete(source_term, target_term)
60
- check_glossary_exists
52
+ raise GlossaryNotFound unless File.exists?(@path)
61
53
 
62
- glossary = load_glossary_yml
54
+ glossary = load_glossary_yml(@path)
63
55
  target_index = find_term_index(glossary, source_term, target_term)
64
56
  if target_index
65
57
  glossary.delete_at(target_index)
66
58
  dump_glossary(glossary)
67
59
  else
68
- raise TermError, "source_term:#{source_term} target_term:#{target_term} not found in glossary #{@path}"
60
+ raise TermError, "Can't found term '#{source_term}: #{target_term}' in '#{@glossary}'"
69
61
  end
70
62
  end
71
63
 
72
64
  def lookup(source_term)
73
- check_glossary_exists
65
+ raise GlossaryDBNotFound unless File.exists?(logaling_db_home)
74
66
 
75
- glossarydb = Logaling::GlossaryDB.new
76
- glossarydb.open(logaling_db_home, "utf8") do |db|
77
- glossaries = db.lookup(source_term)
78
- glossaries.reject! do |term|
67
+ terms = []
68
+ Logaling::GlossaryDB.open(logaling_db_home, "utf8") do |db|
69
+ terms = db.lookup(source_term)
70
+ terms.reject! do |term|
79
71
  term[:source_language] != @source_language || term[:target_language] != @target_language
80
72
  end
81
- if glossaries.empty?
82
- raise TermError, "source-term <#{source_term}> not found"
83
- end
84
- # order by glossary
85
- specified = glossaries.select{|term| term[:name] == @glossary}
86
- other = glossaries.select{|term| term[:name] != @glossary}
87
- glossaries = specified.concat(other)
88
-
89
- puts "\nlookup word : #{source_term}"
90
- glossaries.each do |term|
91
- puts "\n #{term[:source_term]}\n"
92
- puts " #{term[:target_term]}\n"
93
- puts " note:#{term[:note]}"
94
- puts " glossary:#{term[:name]}"
73
+ unless terms.empty?
74
+ # order by glossary
75
+ specified = terms.select{|term| term[:name] == @glossary}
76
+ other = terms.select{|term| term[:name] != @glossary}
77
+ terms = specified.concat(other)
95
78
  end
96
79
  end
80
+ terms
97
81
  end
98
82
 
99
83
  def index
100
84
  projects = Dir.glob(File.join(LOGALING_HOME, "projects", "*"))
101
- glossarydb = Logaling::GlossaryDB.new
102
- glossarydb.open(logaling_db_home, "utf8") do |db|
103
- db.recreate_table(logaling_db_home)
85
+
86
+ Logaling::GlossaryDB.open(logaling_db_home, "utf8") do |db|
87
+ db.recreate_table
104
88
  projects.each do |project|
105
- db.load_glossaries(File.join(project, "glossary"))
89
+ get_glossaries(project).each do |glossary, name, source_language, target_language|
90
+ db.index_glossary(glossary, name, source_language, target_language)
91
+ end
106
92
  end
107
93
  end
108
94
  end
109
95
 
110
96
  private
111
- def load_glossary_yml
112
- YAML::load_file(@path) || []
97
+ def load_glossary(file)
98
+ case File.extname(file)
99
+ when ".csv"
100
+ load_glossary_csv(file)
101
+ when ".tsv"
102
+ load_glossary_tsv(file)
103
+ when ".yml"
104
+ load_glossary_yml(file)
105
+ end
106
+ end
107
+
108
+ def get_glossaries(path)
109
+ glob_list = %w(yml tsv csv).map{|type| File.join(path, "glossary", "*.#{type}") }
110
+ Dir.glob(glob_list).map do |file|
111
+ name, source_language, target_language = File::basename(file, ".*").split(".")
112
+ [load_glossary(file), name, source_language, target_language]
113
+ end
114
+ end
115
+
116
+ def load_glossary_yml(path)
117
+ YAML::load_file(path) || []
118
+ end
119
+
120
+ def load_glossary_tsv(path)
121
+ load_glossary_csv(path, "\t")
122
+ end
123
+
124
+ def load_glossary_csv(path, sep=",")
125
+ glossary = []
126
+ CSV.open(path, "r", {:col_sep => sep}) do |csv|
127
+ csv.each do |row|
128
+ glossary << {"source_term" => row[0], "target_term" => row[1], "note" => ""} if row.size >= 2
129
+ end
130
+ end
131
+ glossary
113
132
  end
114
133
 
115
134
  def logaling_db_home
@@ -137,22 +156,6 @@ module Logaling
137
156
  target_terms(source_term).any?{|data| data['target_term'] == target_term }
138
157
  end
139
158
 
140
- def check_glossarydir_unexists
141
- unless File.exists?(File.dirname(@path))
142
- raise CommandFailed, "glossary path #{File.dirname(@path)} not found"
143
- end
144
- end
145
-
146
- def check_glossary_unexists
147
- check_glossarydir_unexists
148
- raise CommandFailed, "glossary #{@path} already exists" if File.exists?(@path)
149
- end
150
-
151
- def check_glossary_exists
152
- check_glossarydir_unexists
153
- FileUtils.touch(@path) unless File.exists?(@path)
154
- end
155
-
156
159
  def target_terms(source_term, path=@path)
157
160
  target_terms = []
158
161
  glossaly = YAML::load_file(path) || []
@@ -8,6 +8,10 @@ require 'csv'
8
8
 
9
9
  module Logaling
10
10
  class GlossaryDB
11
+ def self.open(base_path, encoding, &blk)
12
+ blk ? GlossaryDB.new.open(base_path, encoding, &blk) : GlossaryDB.new.open(base_path, encoding)
13
+ end
14
+
11
15
  def initialize
12
16
  @database = nil
13
17
  end
@@ -30,11 +34,8 @@ module Logaling
30
34
  end
31
35
  end
32
36
 
33
- def recreate_table(base_path)
34
- path = File.join(base_path, "logaling.db.tables")
35
- if File.exist?(path)
36
- remove_schema
37
- end
37
+ def recreate_table
38
+ remove_schema
38
39
  populate_schema
39
40
  end
40
41
 
@@ -43,38 +44,12 @@ module Logaling
43
44
  @database = nil
44
45
  end
45
46
 
46
- def closed?
47
- @database.nil? or @database.closed?
48
- end
49
-
50
- def load_glossary(file)
51
- case extname = File.extname(file)
52
- when ".tsv", ".csv"
53
- sep = extname == ".tsv" ? "\t" : ","
54
- glossary = []
55
- CSV.open(file, "r", {:col_sep => sep}) do |csv|
56
- csv.each do |row|
57
- glossary << {"source_term" => row[0], "target_term" => row[1], "note" => ""} if row.size >= 2
58
- end
59
- end
60
- glossary
61
- when ".yml"
62
- YAML::load_file(file)
63
- end
64
- end
65
-
66
- def load_glossaries(path)
67
- file_list = get_file_list(path, ["yml", "tsv", "csv"])
68
- file_list.each do |file|
69
- name, source_language, target_language = File::basename(file, ".*").split(".")
70
- glossary = load_glossary(file)
71
- next if !glossary
72
- glossary.each do |term|
73
- source_term = term['source_term']
74
- target_term = term['target_term']
75
- note = term['note']
76
- add_glossary(name, source_language, target_language, source_term, target_term, note)
77
- end
47
+ def index_glossary(glossary, name, source_language, target_language)
48
+ glossary.each do |term|
49
+ source_term = term['source_term']
50
+ target_term = term['target_term']
51
+ note = term['note']
52
+ add_glossary(name, source_language, target_language, source_term, target_term, note)
78
53
  end
79
54
  end
80
55
 
@@ -141,15 +116,13 @@ module Logaling
141
116
 
142
117
  def remove_schema
143
118
  Groonga::Schema.define do |schema|
144
- schema.remove_table("glossaries")
145
- schema.remove_table("terms")
119
+ schema.remove_table("glossaries") if Groonga["glossaries"]
120
+ schema.remove_table("terms") if Groonga["terms"]
146
121
  end
147
122
  end
148
123
 
149
- def get_file_list(path, types)
150
- glob_list = types.map{|type| File.join(path, "*.#{type}") }
151
- Dir.glob(glob_list)
124
+ def closed?
125
+ @database.nil? or @database.closed?
152
126
  end
153
-
154
127
  end
155
128
  end
data/lib/logaling.rb CHANGED
@@ -6,4 +6,6 @@ module Logaling
6
6
  class LogalingError < RuntimeError; end
7
7
  class TermError < LogalingError; end
8
8
  class CommandFailed < LogalingError; end
9
+ class GlossaryNotFound < LogalingError; end
10
+ class GlossaryDBNotFound < LogalingError; end
9
11
  end
@@ -7,10 +7,13 @@ describe Logaling::Command do
7
7
  let(:glossary_path) { Logaling::Glossary.build_path('spec', 'en', 'ja') }
8
8
  let(:target_project_path) { File.join(LOGALING_HOME, "projects", "spec") }
9
9
 
10
+ before do
11
+ FileUtils.remove_entry_secure(Logaling::Command::LOGALING_CONFIG, true)
12
+ FileUtils.remove_entry_secure(File.join(LOGALING_HOME, 'projects', 'spec'), true)
13
+ end
14
+
10
15
  describe '#new' do
11
16
  before do
12
- FileUtils.remove_entry_secure(Logaling::Command::LOGALING_CONFIG, true)
13
- FileUtils.remove_file(target_project_path) if File.exist?(target_project_path)
14
17
  @project_counts = Dir[File.join(LOGALING_HOME, "projects", "*")].size
15
18
  end
16
19
 
@@ -61,7 +64,6 @@ describe Logaling::Command do
61
64
 
62
65
  describe '#register' do
63
66
  before do
64
- FileUtils.remove_file(target_project_path) if File.exist?(target_project_path)
65
67
  @project_counts = Dir[File.join(LOGALING_HOME, "projects", "*")].size
66
68
  end
67
69
 
@@ -76,7 +78,7 @@ describe Logaling::Command do
76
78
  end
77
79
 
78
80
  it "print message \"Try 'loga new' first.\"" do
79
- @stdout.should == "Try 'loga new' first.\n"
81
+ @stdout.should be_include "Try 'loga new' first.\n"
80
82
  end
81
83
  end
82
84
 
@@ -108,22 +110,19 @@ describe Logaling::Command do
108
110
  @stdout = capture(:stdout) {command.unregister}
109
111
  end
110
112
 
111
- it 'unregister nothing' do
113
+ it 'should not register nothing' do
112
114
  Dir[File.join(LOGALING_HOME, "projects", "*")].size.should == @project_counts
113
115
  end
114
116
 
115
- it "print message \".logaling can't be found.\"" do
116
- @stdout.should == ".logaling can't be found.\n"
117
+ it "should print message \"Can't found .logaling in [...]\"" do
118
+ @stdout.should be_include "Can't found .logaling in"
117
119
  end
118
120
  end
119
121
 
120
122
  context 'when find .logaling' do
121
- before do
122
- command.new('spec', 'en', 'ja')
123
- end
124
-
125
123
  context 'and .logaling registered' do
126
124
  before do
125
+ command.new('spec', 'en', 'ja')
127
126
  command.register
128
127
  command.unregister
129
128
  end
@@ -136,42 +135,21 @@ describe Logaling::Command do
136
135
 
137
136
  context "and .logaling is not registered" do
138
137
  before do
138
+ command.options = base_options.merge("no-register" => true)
139
+ command.new('spec', 'en', 'ja')
139
140
  @stdout = capture(:stdout) {command.unregister}
140
141
  end
141
142
 
142
- it "print message \".logaling is not yet registered.\"" do
143
- @stdout.should == ".logaling is not yet registered.\n"
143
+ it "print message \"<glossary name> is not yet registered.\"" do
144
+ @stdout.should == "spec is not yet registered.\n"
144
145
  end
145
146
  end
146
147
  end
147
148
  end
148
149
 
149
- describe '#create' do
150
- before do
151
- FileUtils.remove_entry_secure(File.join(LOGALING_HOME, 'projects', 'spec'), true)
152
- end
153
-
154
- context 'with arguments show non-existent glossary' do
155
- before do
156
- command.new('spec', 'en', 'ja')
157
- command.register
158
- command.create
159
- end
160
-
161
- it "glossary yaml should be newly created" do
162
- File.exists?(glossary_path).should be_true
163
- end
164
- end
165
-
166
- after do
167
- FileUtils.remove_entry_secure(Logaling::Command::LOGALING_CONFIG, true)
168
- end
169
- end
170
-
171
150
  describe '#add' do
172
151
  before do
173
- FileUtils.remove_entry_secure(File.join(LOGALING_HOME, 'projects', 'spec'), true)
174
- FileUtils.mkdir_p(File.dirname(glossary_path))
152
+ command.new('spec', 'en', 'ja')
175
153
  end
176
154
 
177
155
  context 'with arguments have only bilingual pair' do
@@ -209,8 +187,7 @@ describe Logaling::Command do
209
187
 
210
188
  describe "#update" do
211
189
  before do
212
- FileUtils.remove_entry_secure(File.join(LOGALING_HOME, 'projects', 'spec'), true)
213
- FileUtils.mkdir_p(File.dirname(glossary_path))
190
+ command.new('spec', 'en', 'ja')
214
191
  command.add("spec", "テスト", "備考")
215
192
  end
216
193
 
@@ -243,68 +220,25 @@ describe Logaling::Command do
243
220
  end
244
221
  end
245
222
 
246
- describe '#index' do
247
- before do
248
- FileUtils.remove_entry_secure(File.join(LOGALING_HOME, 'projects', 'spec'), true)
249
- FileUtils.mkdir_p(File.dirname(glossary_path))
250
- command.add("spec", "スペック", "備考")
251
- command.index
252
- end
253
-
254
- context 'glossary files exist in some project' do
255
- db_home = File.join(LOGALING_HOME, "db")
256
- db = Logaling::GlossaryDB.new
257
-
258
- subject { db.open(db_home, "utf8"){|db| records = db.lookup("spec")} }
259
-
260
- it 'glossaries should be indexed' do
261
- subject.should == [{:name=>"spec", :source_language=>"en", :target_language=>"ja", :source_term=>"spec", :target_term=>"スペック", :note=>"備考"}]
262
- end
263
- end
264
- end
265
-
266
223
  describe '#lookup' do
267
- let(:base_options2) { {"glossary"=>"spec2", "source-language"=>"en", "target-language"=>"ja"} }
268
- let(:command2) { Logaling::Command.new([], base_options2) }
269
- let(:glossary_path2) { Logaling::Glossary.build_path('spec2', 'en', 'ja') }
270
-
271
224
  before do
272
- FileUtils.remove_entry_secure(File.join(LOGALING_HOME, 'projects', 'spec'), true)
273
- FileUtils.mkdir_p(File.dirname(glossary_path))
225
+ command.new('spec', 'en', 'ja')
226
+ command.add("spec", "スペック", "備考")
274
227
  end
275
228
 
276
229
  context 'with arguments exist term' do
277
230
  before do
278
- command.add("spec", "スペック", "備考")
279
- FileUtils.mkdir_p(File.dirname(glossary_path2))
280
- command2.add("spec", "スペック")
231
+ @stdout = capture(:stdout) {command.lookup("spec")}
281
232
  end
282
233
 
283
234
  it 'succeed at find by term without command.index' do
284
- stdout = capture(:stdout) {command.lookup("spec")}
285
- stdout.should == <<-EOM
286
-
287
- lookup word : spec
288
-
289
- spec
290
- スペック
291
- note:備考
292
- glossary:spec
293
-
294
- spec
295
- スペック
296
- note:
297
- glossary:spec2
298
- EOM
299
- end
300
-
301
- after do
302
- FileUtils.remove_entry_secure(File.join(LOGALING_HOME, 'projects', 'spec2'), true)
235
+ @stdout.should be_include "glossary:spec"
303
236
  end
304
237
  end
305
238
  end
306
239
 
307
240
  after do
241
+ FileUtils.remove_entry_secure(Logaling::Command::LOGALING_CONFIG, true)
308
242
  FileUtils.remove_entry_secure(File.join(LOGALING_HOME, 'projects', 'spec'), true)
309
243
  end
310
244
  end
@@ -13,29 +13,6 @@ module Logaling
13
13
  FileUtils.mkdir_p(File.dirname(glossary_path))
14
14
  end
15
15
 
16
- describe '#create' do
17
- context 'when glossary already exists' do
18
- before do
19
- FileUtils.touch(glossary_path)
20
- end
21
-
22
- it {
23
- -> { glossary.create }.should raise_error(Logaling::CommandFailed)
24
- }
25
- end
26
-
27
- context 'newly create' do
28
- before do
29
- glossary.create
30
- end
31
-
32
- # <glossary name>.source-language.target_language.yml というファイル名で用語集が作成されること
33
- it 'specified glossary should has created' do
34
- File.exists?(glossary_path).should be_true
35
- end
36
- end
37
- end
38
-
39
16
  describe '#add' do
40
17
  context 'with arguments show new bilingual pair' do
41
18
  before do
@@ -70,16 +47,6 @@ module Logaling
70
47
  term.should_not be_nil
71
48
  end
72
49
  end
73
-
74
- context "when the glossary dir not found" do
75
- before do
76
- FileUtils.remove_entry_secure(File.join(LOGALING_HOME, 'projects', 'spec'), true)
77
- end
78
-
79
- it {
80
- -> { glossary.add("test", "テスト", "テスト") }.should raise_error(Logaling::CommandFailed)
81
- }
82
- end
83
50
  end
84
51
 
85
52
  describe '#update' do
@@ -121,21 +88,14 @@ module Logaling
121
88
  describe '#lookup' do
122
89
  before do
123
90
  glossary.add("user", "ユーザ", "ユーザーではない")
91
+ glossary.index
124
92
  end
125
93
 
126
94
  context 'with arguments show existing bilingual pair' do
127
- it 'succeed at find by term' do
128
- glossary.index
129
- stdout = capture(:stdout) {glossary.lookup("user")}
130
- stdout.should == <<-EOM
95
+ subject {glossary.lookup("user")}
131
96
 
132
- lookup word : user
133
-
134
- user
135
- ユーザ
136
- note:ユーザーではない
137
- glossary:spec
138
- EOM
97
+ it 'succeed at find by term' do
98
+ should be_include({:name=>"spec", :source_language=>"en", :target_language=>"ja", :source_term=>"user", :target_term=>"ユーザ", :note=>"ユーザーではない"})
139
99
  end
140
100
  end
141
101
 
@@ -149,23 +109,10 @@ lookup word : user
149
109
  glossary.index
150
110
  end
151
111
 
152
- it 'succeed at find by term' do
153
- glossary.index
154
- stdout = capture(:stdout) {glossary.lookup("user")}
155
- stdout.should == <<-EOM
112
+ subject {glossary.lookup("user")}
156
113
 
157
- lookup word : user
158
-
159
- user
160
- ユーザ
161
- note:ユーザーではない
162
- glossary:spec
163
-
164
- user
165
- ユーザー
166
- note:
167
- glossary:spec
168
- EOM
114
+ it 'succeed at find by term' do
115
+ should be_include({:name=>"spec", :source_language=>"en", :target_language=>"ja", :source_term=>"user", :target_term=>"ユーザー", :note=>nil})
169
116
  end
170
117
 
171
118
  after do
@@ -191,7 +138,7 @@ lookup word : user
191
138
  subject { logaling_db.open(db_home, "utf8"){|db| logaling_db.lookup("spec")} }
192
139
 
193
140
  it 'glossaries should be indexed' do
194
- should == [{:name=>"spec", :source_language=>"en", :target_language=>"ja", :source_term=>"spec", :target_term=>"スペック", :note=>"備考"}]
141
+ should be_include({:name=>"spec", :source_language=>"en", :target_language=>"ja", :source_term=>"spec", :target_term=>"スペック", :note=>"備考"})
195
142
  end
196
143
 
197
144
  after do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logaling-command
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,11 +13,11 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2011-11-28 00:00:00.000000000Z
16
+ date: 2011-11-30 00:00:00.000000000Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: thor
20
- requirement: &2152368760 !ruby/object:Gem::Requirement
20
+ requirement: &2153858740 !ruby/object:Gem::Requirement
21
21
  none: false
22
22
  requirements:
23
23
  - - ! '>='
@@ -25,10 +25,10 @@ dependencies:
25
25
  version: 0.14.6
26
26
  type: :runtime
27
27
  prerelease: false
28
- version_requirements: *2152368760
28
+ version_requirements: *2153858740
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: bundler
31
- requirement: &2152368000 !ruby/object:Gem::Requirement
31
+ requirement: &2153857740 !ruby/object:Gem::Requirement
32
32
  none: false
33
33
  requirements:
34
34
  - - ! '>='
@@ -36,10 +36,10 @@ dependencies:
36
36
  version: '1.0'
37
37
  type: :runtime
38
38
  prerelease: false
39
- version_requirements: *2152368000
39
+ version_requirements: *2153857740
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: rake
42
- requirement: &2152367420 !ruby/object:Gem::Requirement
42
+ requirement: &2153837940 !ruby/object:Gem::Requirement
43
43
  none: false
44
44
  requirements:
45
45
  - - ! '>='
@@ -47,10 +47,10 @@ dependencies:
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
- version_requirements: *2152367420
50
+ version_requirements: *2153837940
51
51
  - !ruby/object:Gem::Dependency
52
52
  name: rspec
53
- requirement: &2152366640 !ruby/object:Gem::Requirement
53
+ requirement: &2153837240 !ruby/object:Gem::Requirement
54
54
  none: false
55
55
  requirements:
56
56
  - - ! '>='
@@ -58,7 +58,7 @@ dependencies:
58
58
  version: '0'
59
59
  type: :development
60
60
  prerelease: false
61
- version_requirements: *2152366640
61
+ version_requirements: *2153837240
62
62
  description: A command line interface for logaling.
63
63
  email:
64
64
  - koji.shimada@enishi-tech.com
@@ -82,7 +82,6 @@ files:
82
82
  - lib/logaling/glossary_db.rb
83
83
  - logaling-command.gemspec
84
84
  - spec/logaling/command_spec.rb
85
- - spec/logaling/glossary_db_spec.rb
86
85
  - spec/logaling/glossary_spec.rb
87
86
  - spec/spec_helper.rb
88
87
  homepage: http://logaling.github.com/
@@ -111,6 +110,5 @@ specification_version: 3
111
110
  summary: A command line interface for logaling.
112
111
  test_files:
113
112
  - spec/logaling/command_spec.rb
114
- - spec/logaling/glossary_db_spec.rb
115
113
  - spec/logaling/glossary_spec.rb
116
114
  - spec/spec_helper.rb
@@ -1,75 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require File.join(File.dirname(__FILE__), "..", "spec_helper")
3
-
4
- describe Logaling::GlossaryDB do
5
- let(:glossary_path) { Logaling::Glossary.build_path('spec', 'en', 'ja') }
6
- let(:tsv_path) { File.join(File.dirname(glossary_path), 'spec.en.ja.tsv') }
7
- let(:csv_path) { File.join(File.dirname(glossary_path), 'spec.en.ja.csv') }
8
- let(:glossary_db) { Logaling::GlossaryDB.new }
9
-
10
- before do
11
- FileUtils.remove_entry_secure(File.join(LOGALING_HOME, 'projects', 'spec'), true)
12
- FileUtils.mkdir_p(File.dirname(glossary_path))
13
- end
14
-
15
- describe '#load_glossary' do
16
- context 'with argument yml' do
17
- before do
18
- FileUtils.touch(glossary_path)
19
- term = [{'source_term' => 'spec', 'target_term' => 'スペック', 'note' => 'スペック'}]
20
- File.open(glossary_path, "w"){|f| f.puts(term.to_yaml)}
21
- end
22
-
23
- subject { glossary_db.load_glossary(glossary_path) }
24
-
25
- it 'should return formatted glossary' do
26
- should == [{'source_term' => 'spec', 'target_term' => 'スペック', 'note' => 'スペック'}]
27
- end
28
-
29
- after do
30
- FileUtils.remove_entry_secure(glossary_path, true)
31
- end
32
- end
33
-
34
- context 'with argument tsv' do
35
- before do
36
- FileUtils.touch(tsv_path)
37
- term = "spec\tスペック"
38
- File.open(tsv_path, "w"){|f| f.puts(term)}
39
- end
40
-
41
- subject { glossary_db.load_glossary(tsv_path) }
42
-
43
- it 'should return formatted glossary' do
44
- should == [{'source_term' => 'spec', 'target_term' => 'スペック', 'note' => ''}]
45
- end
46
-
47
- after do
48
- FileUtils.remove_entry_secure(tsv_path, true)
49
- end
50
- end
51
-
52
- context 'with argument csv' do
53
- before do
54
- FileUtils.touch(csv_path)
55
- term = "spec,スペック,備考\ntest\n"
56
- File.open(csv_path, "w"){|f| f.puts(term)}
57
- end
58
-
59
- subject { glossary_db.load_glossary(csv_path) }
60
-
61
- it 'should return formatted glossary' do
62
- should == [{'source_term' => 'spec', 'target_term' => 'スペック', 'note' => ''}]
63
- end
64
-
65
- after do
66
- FileUtils.remove_entry_secure(csv_path, true)
67
- end
68
- end
69
- end
70
-
71
- after do
72
- FileUtils.remove_entry_secure(File.join(LOGALING_HOME, 'projects', 'spec'), true)
73
- end
74
- end
75
-