logaling-command 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -17,7 +17,8 @@ require 'open-uri'
17
17
  require 'nokogiri'
18
18
  module Logaling
19
19
  class Tmx < ExternalGlossary
20
- description 'TMX 1.4b formatted glossary (http://www.gala-global.org/oscarStandards/tmx/)'
20
+ description 'TMX 1.4b formatted glossary'
21
+ url 'http://www.gala-global.org/oscarStandards/tmx/'
21
22
  source_language 'en'
22
23
  target_language 'ja'
23
24
  output_format 'csv'
@@ -51,6 +51,10 @@ class Logaling::ExternalGlossary
51
51
  @description ||= val
52
52
  end
53
53
 
54
+ def url val=nil
55
+ @url ||= val
56
+ end
57
+
54
58
  def source_language val=nil
55
59
  @source_language ||= val
56
60
  end
@@ -34,7 +34,7 @@ module Logaling::GlossarySources
34
34
  end
35
35
 
36
36
  def add(source_term, target_term, note)
37
- FileUtils.touch(source_path) unless File.exist?(source_path)
37
+ dump_glossary_source([]) unless File.exist?(source_path)
38
38
 
39
39
  glossary_source = self.load
40
40
  glossary_source << build_term(source_term, target_term, note)
@@ -118,7 +118,7 @@ module Logaling::GlossarySources
118
118
 
119
119
  def dump_glossary_source(glossary_source)
120
120
  File.open(source_path, "w") do |f|
121
- f.puts(glossary_source.to_yaml)
121
+ YAML.dump(glossary_source, f)
122
122
  end
123
123
  end
124
124
  end
@@ -45,7 +45,7 @@ module Logaling
45
45
  File.basename(@path)
46
46
  end
47
47
 
48
- def find_glossary(source_language, target_language)
48
+ def glossary(source_language, target_language)
49
49
  Logaling::Glossary.new(name, source_language, target_language, self)
50
50
  end
51
51
 
@@ -57,13 +57,25 @@ module Logaling
57
57
  @repository.logaling_db_home
58
58
  end
59
59
 
60
+ def glossaries
61
+ glossaries = all_glossary_source_path.map do |source_path|
62
+ name, source_language, target_language, type = File.basename(source_path).split(/\./)
63
+ glossary(source_language, target_language)
64
+ end
65
+ glossaries.uniq{|glossary| glossary.to_s }
66
+ end
67
+
60
68
  def glossary_sources
61
- all_glossary_source_path = Dir.glob(File.join(glossary_source_path, "*"))
62
69
  all_glossary_source_path.map do |source_path|
63
70
  name, source_language, target_language, type = File.basename(source_path).split(/\./)
64
- GlossarySource.create(source_path, find_glossary(source_language, target_language))
71
+ GlossarySource.create(source_path, glossary(source_language, target_language))
65
72
  end
66
73
  end
74
+
75
+ private
76
+ def all_glossary_source_path
77
+ Dir.glob(File.join(glossary_source_path, "*"))
78
+ end
67
79
  end
68
80
 
69
81
  class ImportedProject < Project
@@ -73,7 +85,7 @@ module Logaling
73
85
 
74
86
  def glossary_sources
75
87
  name, source_language, target_language, type = File.basename(@path).split(/\./)
76
- [GlossarySource.create(@path, find_glossary(source_language, target_language))]
88
+ [GlossarySource.create(@path, glossary(source_language, target_language))]
77
89
  end
78
90
  end
79
91
  end
@@ -41,7 +41,7 @@ module Logaling
41
41
 
42
42
  def unregister(project)
43
43
  raise Logaling::ProjectNotFound unless project
44
- FileUtils.remove_entry_secure(project.path, true)
44
+ FileUtils.rm_rf(project.path, :secure => true)
45
45
  end
46
46
 
47
47
  def import(glossary_source)
@@ -24,7 +24,7 @@ describe Logaling::Command::Application do
24
24
  let(:command) { Logaling::Command::Application.new([], base_options) }
25
25
  let(:target_project_path) { File.join(logaling_home, "projects", "spec") }
26
26
  let(:repository) { Logaling::Repository.new(logaling_home) }
27
- let(:glossary) { repository.find_project('spec').find_glossary('en', 'ja') }
27
+ let(:glossary) { repository.find_project('spec').glossary('en', 'ja') }
28
28
  let(:glossary_source_path) { glossary.glossary_source.source_path }
29
29
 
30
30
  before do
@@ -22,11 +22,11 @@ module Logaling
22
22
  describe Glossary do
23
23
  let(:logaling_home) { @logaling_home }
24
24
  let(:repository) { Logaling::Repository.new(logaling_home) }
25
- let(:glossary) { repository.find_project('spec').find_glossary('en', 'ja') }
25
+ let(:glossary) { repository.find_project('spec').glossary('en', 'ja') }
26
26
  let(:glossary_source_path) { glossary.glossary_source.source_path }
27
27
 
28
28
  before do
29
- FileUtils.remove_entry_secure(File.join(logaling_home, 'projects', 'spec'), true)
29
+ FileUtils.rm_rf(File.join(logaling_home, 'projects', 'spec'), :secure => true)
30
30
  FileUtils.mkdir_p(File.join(logaling_home, 'projects', 'spec'))
31
31
  end
32
32
 
@@ -170,7 +170,7 @@ module Logaling
170
170
  end
171
171
 
172
172
  after do
173
- FileUtils.remove_entry_secure(File.join(logaling_home, 'projects', 'spec'), true)
173
+ FileUtils.rm_rf(File.join(logaling_home, 'projects', 'spec'), :secure => true)
174
174
  end
175
175
  end
176
176
  end
@@ -0,0 +1,67 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2012 Miho SUZUKI
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ require File.join(File.dirname(__FILE__), "..", "spec_helper")
19
+ require "fileutils"
20
+
21
+ module Logaling
22
+ describe Project do
23
+ let(:logaling_home) { @logaling_home }
24
+ let(:repository) { Logaling::Repository.new(logaling_home) }
25
+ let(:project_path) { File.join(logaling_home, 'projects', 'spec') }
26
+ let(:project) { repository.find_project("spec") }
27
+
28
+ before do
29
+ FileUtils.rm_rf(project_path, :secure => true)
30
+ FileUtils.mkdir_p(File.join(project_path, "glossary"))
31
+ end
32
+
33
+ describe "#glossaries" do
34
+ before do
35
+ FileUtils.touch(File.join(project_path, "glossary", "spec.en.ja.yml"))
36
+ end
37
+
38
+ context "project has only 'en-ja' glossary" do
39
+ it "should be include 'en-ja' glossary" do
40
+ project.glossaries.map(&:to_s).should be_include "spec.en.ja"
41
+ end
42
+ end
43
+
44
+ context "project has 'en-ja' 'fr-ja' glossaries" do
45
+ before do
46
+ FileUtils.touch(File.join(project_path, "glossary", "spec.fr.ja.yml"))
47
+ end
48
+
49
+ it "should be include 'en-ja' 'fr-ja' glossaries" do
50
+ %w(spec.en.ja spec.fr.ja).each do |glossary_name|
51
+ project.glossaries.map(&:to_s).should be_include glossary_name
52
+ end
53
+ end
54
+ end
55
+
56
+ context "project has two 'en-ja' glossary sources" do
57
+ before do
58
+ FileUtils.touch(File.join(project_path, "glossary", "spec.en.ja.csv"))
59
+ end
60
+
61
+ it "should count as one glossary" do
62
+ project.glossaries.size.should == 1
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -16,17 +16,18 @@
16
16
  # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
17
 
18
18
  require File.join(File.dirname(__FILE__), "..", "spec_helper")
19
+ require 'yaml'
19
20
  require "fileutils"
20
21
 
21
22
  module Logaling
22
23
  describe Repository do
23
24
  let(:logaling_home) { @logaling_home }
24
25
  let(:repository) { Logaling::Repository.new(logaling_home) }
25
- let(:glossary) { repository.find_project('spec').find_glossary('en', 'ja') }
26
+ let(:glossary) { repository.find_project('spec').glossary('en', 'ja') }
26
27
  let(:glossary_source_path) { glossary.glossary_source.source_path }
27
28
 
28
29
  before do
29
- FileUtils.remove_entry_secure(File.join(logaling_home, 'projects', 'spec'), true)
30
+ FileUtils.rm_rf(File.join(logaling_home, 'projects', 'spec'), :secure => true)
30
31
  FileUtils.mkdir_p(File.join(logaling_home, 'projects', 'spec'))
31
32
  end
32
33
 
@@ -103,7 +104,7 @@ module Logaling
103
104
  end
104
105
 
105
106
  after do
106
- FileUtils.remove_entry_secure(tsv_path, true)
107
+ FileUtils.rm_rf(tsv_path, :secure => true)
107
108
  end
108
109
  end
109
110
  end
@@ -114,7 +115,9 @@ module Logaling
114
115
 
115
116
  context 'when yml file as glossary exists' do
116
117
  before do
117
- FileUtils.touch(glossary_source_path)
118
+ File.open(glossary_source_path, 'w') do |f|
119
+ YAML.dump([], f)
120
+ end
118
121
  glossary.add("spec_logaling", "スペック", "備考")
119
122
  repository.index
120
123
  @terms = repository.lookup("spec_logaling", glossary)
@@ -125,7 +128,7 @@ module Logaling
125
128
  end
126
129
 
127
130
  after do
128
- FileUtils.remove_entry_secure(glossary_source_path, true)
131
+ FileUtils.rm_rf(glossary_source_path, :secure => true)
129
132
  end
130
133
  end
131
134
 
@@ -142,7 +145,7 @@ module Logaling
142
145
  end
143
146
 
144
147
  after do
145
- FileUtils.remove_entry_secure(tsv_path, true)
148
+ FileUtils.rm_rf(tsv_path, :secure => true)
146
149
  end
147
150
  end
148
151
 
@@ -159,13 +162,13 @@ module Logaling
159
162
  end
160
163
 
161
164
  after do
162
- FileUtils.remove_entry_secure(csv_path, true)
165
+ FileUtils.rm_rf(csv_path, :secure => true)
163
166
  end
164
167
  end
165
168
  end
166
169
 
167
170
  after do
168
- FileUtils.remove_entry_secure(File.join(logaling_home, 'projects', 'spec'), true)
171
+ FileUtils.rm_rf(File.join(logaling_home, 'projects', 'spec'), :secure => true)
169
172
  end
170
173
  end
171
174
  end
data/spec/spec_helper.rb CHANGED
@@ -43,7 +43,7 @@ RSpec.configure do |config|
43
43
  end
44
44
 
45
45
  config.after(:suite) do
46
- FileUtils.remove_entry_secure(LOGALING_HOME, true)
46
+ FileUtils.rm_rf(LOGALING_HOME, :secure => true)
47
47
  end
48
48
 
49
49
  alias :silence :capture
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.1.6
4
+ version: 0.1.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2012-06-29 00:00:00.000000000 Z
16
+ date: 2012-07-30 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: thor
@@ -157,6 +157,7 @@ extra_rdoc_files: []
157
157
  files:
158
158
  - .gitignore
159
159
  - .rspec
160
+ - .travis.yml
160
161
  - CHANGES
161
162
  - COPYING
162
163
  - Gemfile
@@ -175,8 +176,10 @@ files:
175
176
  - lib/logaling/external_glossaries/freebsd_jpman.rb
176
177
  - lib/logaling/external_glossaries/gene95.rb
177
178
  - lib/logaling/external_glossaries/gnome_project.rb
179
+ - lib/logaling/external_glossaries/itil_japanese.rb
178
180
  - lib/logaling/external_glossaries/mozilla_japan.rb
179
181
  - lib/logaling/external_glossaries/postgresql_manual.rb
182
+ - lib/logaling/external_glossaries/resources/ITIL_2011_Japanese_Glossary_v1.0.html
180
183
  - lib/logaling/external_glossaries/tmx.rb
181
184
  - lib/logaling/external_glossary.rb
182
185
  - lib/logaling/glossary.rb
@@ -191,6 +194,7 @@ files:
191
194
  - logaling-command.gemspec
192
195
  - spec/logaling/command_spec.rb
193
196
  - spec/logaling/glossary_spec.rb
197
+ - spec/logaling/project_spec.rb
194
198
  - spec/logaling/repository_spec.rb
195
199
  - spec/spec_helper.rb
196
200
  homepage: http://logaling.github.com/
@@ -220,5 +224,6 @@ summary: A command line interface for logaling.
220
224
  test_files:
221
225
  - spec/logaling/command_spec.rb
222
226
  - spec/logaling/glossary_spec.rb
227
+ - spec/logaling/project_spec.rb
223
228
  - spec/logaling/repository_spec.rb
224
229
  - spec/spec_helper.rb