textmerge 0.1.3 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cli.rb +11 -1
- data/lib/textmerge/merge.rb +17 -2
- data/lib/textmerge/version.rb +1 -1
- data/spec/lib/textmerge_spec.rb +18 -11
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a6cfb042853ab2d6401aa05d9cf2f7e01bf397c6
|
4
|
+
data.tar.gz: c4e3581ebac8392d49e8b1713a244be3b4fccfb4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 42f092e42dea955182be60a2eb47b71007e3500000e54ff032bb4822bc67a824fff5e3d80f707a1d678742697c42cc900163105a2b1e70f1bc86086ab55976bf
|
7
|
+
data.tar.gz: 74024e00b58e6292fe78117f1e97d0dcdbb24c59df6d09d81e1755a05dab1871b174a280a25d9768d10a34595119c037a981024a8e96ac2ae5a587b84cf2224f
|
data/lib/cli.rb
CHANGED
@@ -42,12 +42,22 @@ module Textmerge
|
|
42
42
|
|
43
43
|
desc 'build', 'Build input file template from a config template'
|
44
44
|
method_option :template, aliases: '-t', type: 'string', default: '', :required => true, desc: 'path to your template file'
|
45
|
+
method_option :output, aliases: '-o', type: 'string', default: '', desc: 'path to your output file'
|
45
46
|
def build
|
46
47
|
begin
|
47
48
|
raise ArgumentError, "Missing template" unless !options[:template].empty?
|
48
49
|
template = options[:template]
|
49
50
|
if File.exists?(template)
|
50
|
-
|
51
|
+
merge = Textmerge::Merge.new(options)
|
52
|
+
template = merge.read_template
|
53
|
+
questions = merge.build_input_file(template)
|
54
|
+
filename = ''
|
55
|
+
if options[:output].empty?
|
56
|
+
filename = merge.name_input_file
|
57
|
+
else
|
58
|
+
filename = options[:output]
|
59
|
+
end
|
60
|
+
merge.write_file(questions,filename)
|
51
61
|
end
|
52
62
|
rescue Exception => e
|
53
63
|
say e.message, :red
|
data/lib/textmerge/merge.rb
CHANGED
@@ -25,6 +25,21 @@ module Textmerge
|
|
25
25
|
file.read
|
26
26
|
end
|
27
27
|
|
28
|
+
def build_input_file(template)
|
29
|
+
# Collect questions
|
30
|
+
output = ""
|
31
|
+
questions = get_requests(template)
|
32
|
+
# output hash to string and send to write_file method
|
33
|
+
questions.each do |num,question|
|
34
|
+
output << "#{num}:#{question}\n"
|
35
|
+
end
|
36
|
+
output
|
37
|
+
end
|
38
|
+
|
39
|
+
def name_input_file
|
40
|
+
@template_file.split(".txt")[0] + "-input.txt"
|
41
|
+
end
|
42
|
+
|
28
43
|
def get_responses_from_input_file(data_file = @input_file)
|
29
44
|
collection = []
|
30
45
|
File.open(data_file, 'r') do |file|
|
@@ -55,8 +70,8 @@ module Textmerge
|
|
55
70
|
data
|
56
71
|
end
|
57
72
|
|
58
|
-
def write_file(contents)
|
59
|
-
File.open(
|
73
|
+
def write_file(contents,filename = @output_file)
|
74
|
+
File.open(filename, 'w') {|f| f.write(contents)}
|
60
75
|
end
|
61
76
|
|
62
77
|
protected
|
data/lib/textmerge/version.rb
CHANGED
data/spec/lib/textmerge_spec.rb
CHANGED
@@ -21,37 +21,44 @@ describe Textmerge::Merge do
|
|
21
21
|
this would be some additional text, and then answer 2
|
22
22
|
and we have some more text before ending answer 3
|
23
23
|
Links are Answer 1, answer 2, answer 3." }
|
24
|
+
let(:printed) {"1:First question\n2:Second question\n3:Third question\n" }
|
25
|
+
|
24
26
|
|
25
27
|
context "when reading from input" do
|
26
|
-
it "
|
28
|
+
it "reads from an input file and output a hash of responses" do
|
27
29
|
test_file_path = File.join(File.dirname(__FILE__), "test_input.txt")
|
28
|
-
expect(merge.get_responses_from_input_file(test_file_path)).to eq
|
30
|
+
expect(merge.get_responses_from_input_file(test_file_path)).to eq answers
|
29
31
|
end
|
30
32
|
|
31
|
-
it "
|
32
|
-
merge.get_requests(data).
|
33
|
+
it "reads a file and return an array of questions" do
|
34
|
+
expect(merge.get_requests(data)).to eq(result)
|
33
35
|
expect(merge.get_requests(data)[2]).to eq("Second question")
|
34
36
|
end
|
35
37
|
|
36
|
-
it "
|
38
|
+
it "orders questions properly" do
|
37
39
|
text = "{2:Second question} and the {1:First question}"
|
38
40
|
expect(merge.get_requests(text)[1]).to eq("First question")
|
39
41
|
end
|
40
42
|
|
41
|
-
it "
|
42
|
-
|
43
|
+
it "raises an exception when there is a blank question" do
|
44
|
+
|
43
45
|
end
|
44
46
|
end
|
45
47
|
|
46
48
|
context "when handling input" do
|
47
|
-
it "
|
49
|
+
it "builds responses from our hash of questions" do
|
48
50
|
Textmerge::Merge.any_instance.stub(:ask_basic_question).and_return("Answer 1")
|
49
|
-
merge.get_responses({1=>"Question 1"}).
|
51
|
+
expect(merge.get_responses({1=>"Question 1"})).to eq({1=>"Answer 1"})
|
50
52
|
end
|
51
53
|
|
52
|
-
it "
|
53
|
-
merge.
|
54
|
+
it "creates a list of questions from the template file" do
|
55
|
+
expect(merge.build_input_file(data)).to eq printed
|
54
56
|
end
|
57
|
+
|
58
|
+
it "create an input file name from the original template" do
|
59
|
+
expect(merge.name_input_file("template.txt")).to eq "template-input.txt"
|
60
|
+
end
|
61
|
+
|
55
62
|
end
|
56
63
|
end
|
57
64
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: textmerge
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Simpson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-06-
|
11
|
+
date: 2015-06-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|