textmerge 0.1.3 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 305d040451550c67c9fb08b34db81fd55f87f831
4
- data.tar.gz: a35cf6aebb597b8b94d7f5bd89014839a856a900
3
+ metadata.gz: a6cfb042853ab2d6401aa05d9cf2f7e01bf397c6
4
+ data.tar.gz: c4e3581ebac8392d49e8b1713a244be3b4fccfb4
5
5
  SHA512:
6
- metadata.gz: ab6e9f0fe0e3eed72b57827081539e3d4a5d6c5197479a42e28a4d21db005dd7c8eb31fde3cb4d3c75bb0cd32f7c8e140a49ba2c2307af539e2055c2d8ea0fa7
7
- data.tar.gz: b6639f6ede6020323283cbd830a5783dcd9fe30db4c4c07bbb23e9fef17d6044c3d3cbc2279dda97782a433637086901621136d45e2cd35bafe34d20c5ee1e0a
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
- TextMerge::Build.new(template)
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
@@ -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(@output_file, 'w') {|f| f.write(contents)}
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
@@ -1,3 +1,3 @@
1
1
  module Textmerge
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.5"
3
3
  end
@@ -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 "should read from an input file and output a hash of responses" do
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(answers)
30
+ expect(merge.get_responses_from_input_file(test_file_path)).to eq answers
29
31
  end
30
32
 
31
- it "should read a file and return an array of questions" do
32
- merge.get_requests(data).should eq(result)
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 "should order questions properly" do
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 "should raise an exception when there is a blank question" do
42
- pending "exception testing"
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 "should build responses from our hash of questions" do
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"}).should eq({1=>"Answer 1"})
51
+ expect(merge.get_responses({1=>"Question 1"})).to eq({1=>"Answer 1"})
50
52
  end
51
53
 
52
- it "should merge the responses into our content" do
53
- merge.merge_responses(answers,data).should eq(output)
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.3
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-10 00:00:00.000000000 Z
11
+ date: 2015-06-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler