spout 0.1.0.pre → 0.1.0.rc

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 880fd246ea520f004a09cf9bf2b576d5866c9850
4
- data.tar.gz: 65d2e48269923e7a46cd7448fa8e265c3ad8ac6c
3
+ metadata.gz: e32f497120ec785b137d1c17e742276175bcefb1
4
+ data.tar.gz: fc4b7095bc652ca44c4ad0fc57bcb9b7e393faf1
5
5
  SHA512:
6
- metadata.gz: bad0c66a8fc3e992e3affcd6cff667a749f6acd0db8b858cd53d37af5961f1db83003d98b8f4bb205c111074053d19d82689b41a4f3b16ba93d60fd8835983ed
7
- data.tar.gz: ec2ce69aa8c5157d7d4345ad12d78c91564951afc1c564868c2c8c17dc6993b6a9d82cd52fd6edca05e0329021e3c62a5442f969ef74bdb39073f78f4296a63b
6
+ metadata.gz: 348a4e793232013cfe12d1444ad6e68e802b095e3cc5b6ee0663ae3985ad010cb1d828c099827f86c991a156e6457fce97667b9ca1fc04ef270647c2bd7f4d6f
7
+ data.tar.gz: 559c1d2b2c288d81bd2be68387fce94d15f1ac2cccf03bb17ac56cad7457bc2d9d353a3a33cbc1bbc6c4b6e52c374f3ad525ca8f19131762863bebda090c401b
data/CHANGELOG.md CHANGED
@@ -2,6 +2,17 @@
2
2
 
3
3
  ### Enhancements
4
4
  - Existing Data Dictionaries can be converted to JSON format from a CSV file
5
+ - Recognized columns:
6
+ - `folder`
7
+ - `id`
8
+ - `display_name`
9
+ - `description`
10
+ - `type`
11
+ - `domain`
12
+ - `units`
13
+ - `calculation`
14
+ - `labels`
15
+ - All other columns will go into an `Other` JSON hash
5
16
  - Added a rake task to create CSVs of the JSON data dictionary
6
17
  - Added tests for JSON validity of variables and domains
7
18
  - Added test to check presence/validity of variable type
@@ -13,3 +24,4 @@
13
24
  - `include Spout::Tests::JsonValidation` to verify valid JSON formats of domains and variables
14
25
  - `include Spout::Tests::VariableTypeValidation` to verify valid variable type for variables
15
26
  - `include Spout::Tests::DomainExistenceValidation` to verify existence of domains referenced by variables
27
+ - Added `spout new FOLDER` to create an empty data dictionary in the specified `FOLDER`
data/README.md CHANGED
@@ -25,7 +25,7 @@ spout new my_data_dictionary
25
25
 
26
26
  cd my_data_dictionary
27
27
 
28
- bundle exec rake dd:import CSV=data_dictionary.csv
28
+ spout import CSV=data_dictionary.csv
29
29
  ```
30
30
 
31
31
  ### Test your repository
@@ -57,5 +57,11 @@ Then run either `bundle exec rake` or `spout test` to run your tests
57
57
  Provide an optional version parameter to name the folder the CSVs will be generated in, defaults to 1.0.0 currently.
58
58
 
59
59
  ```
60
- bundle exec rake dd:create [VERSION]
60
+ spout export
61
+ ```
62
+
63
+ or
64
+
65
+ ```
66
+ bundle exec rake dd:create [VERSION=1.0.0]
61
67
  ```
data/lib/spout/actions.rb CHANGED
@@ -1,31 +1,106 @@
1
1
  module Spout
2
2
  class Actions
3
3
 
4
- def help
5
- help_message = <<-EOT
4
+ def interpret(argv)
5
+ case argv.first
6
+ when 'new'
7
+ new_template_dictionary(argv)
8
+ when '--version', '-v', 'version'
9
+ puts "Spout #{Spout::VERSION::STRING}"
10
+ when 'help', '--help', '-h'
11
+ help
12
+ when 'import'
13
+ import_from_csv(argv)
14
+ when 'export'
15
+ system "bundle exec rake dd:create"
16
+ else
17
+ system "bundle exec rake"
18
+ end
19
+ end
20
+
21
+ protected
22
+
23
+ def import_from_csv(argv)
24
+ usage = <<-EOT
25
+
26
+ Usage: spout import CSVFILE
27
+
28
+ The CSVFILE must be the location of a valid CSV file.
29
+
30
+ EOT
31
+
32
+ csv_file = File.join(argv[1].to_s.strip)
33
+ if File.exists?(csv_file)
34
+ system "bundle exec rake dd:import CSV=#{csv_file}"
35
+ else
36
+ puts usage
37
+ end
38
+ end
39
+
40
+ def help
41
+ help_message = <<-EOT
6
42
 
7
43
  Usage: spout COMMAND [ARGS]
8
44
 
9
45
  The most common spout commands are:
10
- test Running the test file (short-cut alias: "t")
11
46
  new Create a new Spout dictionary. "spout new my_dd" creates a
12
47
  new data dictionary called MyDD in "./my_dd"
48
+ test Running the test file (short-cut alias: "t")
49
+ import Import a CSV file into the JSON repository
50
+ export Export the JSON respository to a CSV
13
51
  version Returns the version of Spout
14
52
 
15
53
  EOT
16
- puts help_message
17
- end
54
+ puts help_message
55
+ end
18
56
 
19
- def interpret(argv)
20
- case argv.first
21
- when '--version', '-v', 'version'
22
- puts "Spout #{Spout::VERSION::STRING}"
23
- when 'help', '--help', '-h'
24
- help
25
- else
26
- system "bundle exec rake"
57
+ def new_template_dictionary(argv)
58
+ @full_path = File.join(argv[1].to_s.strip)
59
+ usage = <<-EOT
60
+
61
+ Usage: spout new FOLDER
62
+
63
+ The FOLDER must be empty or new.
64
+
65
+ EOT
66
+
67
+ if Dir.exists?(@full_path) and (Dir.entries(@full_path) - ['.', '..']).size > 0
68
+ puts usage
69
+ exit(0)
70
+ end
71
+
72
+ FileUtils.mkpath(@full_path)
73
+
74
+ copy_file 'gitignore', '.gitignore'
75
+ copy_file 'ruby-version', '.ruby-version'
76
+ copy_file 'travis.yml', '.travis.yml'
77
+ copy_file 'Gemfile'
78
+ copy_file 'Rakefile'
79
+ directory 'domains'
80
+ directory 'variables'
81
+ directory 'test'
82
+ copy_file 'test/dictionary_test.rb'
83
+ copy_file 'test/test_helper.rb'
84
+ puts " run bundle install"
85
+ Dir.chdir(@full_path)
86
+ system "bundle install"
87
+ end
88
+
89
+ private
90
+
91
+ def copy_file(template_file, file_name = '')
92
+ file_name = template_file if file_name == ''
93
+ file_path = File.join(@full_path, file_name)
94
+ template_file_path = File.join(File.expand_path(File.dirname(__FILE__)), "templates", template_file)
95
+ puts " create #{file_name}"
96
+ FileUtils.copy(template_file_path, file_path)
97
+ end
98
+
99
+ def directory(directory_name)
100
+ directory_path = File.join(@full_path, directory_name)
101
+ puts " create #{directory_name}"
102
+ FileUtils.mkpath(directory_path)
27
103
  end
28
- end
29
104
 
30
105
  end
31
106
  end
@@ -22,12 +22,12 @@ namespace :dd do
22
22
  FileUtils.mkpath folder
23
23
 
24
24
  CSV.open("#{folder}/variables.csv", "wb") do |csv|
25
- keys = %w(id display_name description type domain)
25
+ keys = %w(id display_name description type units domain labels calculation)
26
26
  csv << ['folder'] + keys
27
27
  Dir.glob("variables/**/*.json").each do |file|
28
28
  if json = JSON.parse(File.read(file)) rescue false
29
29
  variable_folder = file.gsub(/variables\//, '').split('/')[0..-2].join('/')
30
- csv << [variable_folder] + keys.collect{|key| json[key]}
30
+ csv << [variable_folder] + keys.collect{|key| json[key].kind_of?(Array) ? json[key].join(';') : json[key].to_s}
31
31
  end
32
32
  end
33
33
  end
@@ -53,24 +53,31 @@ namespace :dd do
53
53
  if File.exists?(ENV['CSV'].to_s)
54
54
  CSV.parse( File.open(ENV['CSV'].to_s, 'r:iso-8859-1:utf-8'){|f| f.read}, headers: true ) do |line|
55
55
  row = line.to_hash
56
- next if row['COLUMN'] == ''
57
- folder = File.join('variables', row['FOLDER'])
56
+ next if row['id'] == ''
57
+ folder = File.join('variables', row['folder'])
58
58
  FileUtils.mkpath folder
59
59
  hash = {}
60
- hash['id'] = row['COLUMN']
61
- hash['display_name'] = row['DISPLAY_NAME']
62
- hash['description'] = row['DESCRIPTION'].to_s
63
- hash['type'] = row['VARIABLE_TYPE']
64
- hash['domain'] = row['DOMAIN'] if row['DOMAIN'] != '' and row['DOMAIN'] != nil
65
- hash['units'] = row['UNITS'] if row['UNITS'] != '' and row['UNITS'] != nil
66
- hash['calculation'] = row['CALCULATION'] if row['DOMAIN'] != '' and row['CALCULATION'] != nil
67
- hash['labels'] = row['LABELS'].to_s.split(';') if row['LABELS'].to_s.split(';').size > 0
60
+ id = row.delete('id')
61
+ hash['id'] = id
62
+ hash['display_name'] = row.delete('display_name')
63
+ hash['description'] = row.delete('description').to_s
64
+ hash['type'] = row.delete('type')
65
+ domain = row.delete('domain').to_s
66
+ hash['domain'] = domain if domain != ''
67
+ units = row.delete('units').to_s
68
+ hash['units'] = units if units != ''
69
+ calculation = row.delete('calculation').to_s
70
+ hash['calculation'] = calculation if calculation != ''
71
+ labels = row.delete('labels').to_s.split(';')
72
+ hash['labels'] = labels if labels.size > 0
73
+ hash['other'] = row
68
74
 
69
- File.open(File.join(folder, row['COLUMN'].downcase + '.json'), 'w') do |file|
75
+ file_name = File.join(folder, id.downcase + '.json')
76
+ File.open(file_name, 'w') do |file|
70
77
  file.write(JSON.pretty_generate(hash))
71
78
  end
79
+ puts " create #{file_name}"
72
80
  end
73
- puts "Data Dictionary Imported from CSV."
74
81
  else
75
82
  puts "Please specify a valid CSV file."
76
83
  end
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'spout'
@@ -0,0 +1,2 @@
1
+ require 'spout'
2
+ Spout::Application.new.load_tasks
@@ -0,0 +1,8 @@
1
+ # OS generated files #
2
+ .DS_Store
3
+
4
+ # Project Files
5
+ /Gemfile.lock
6
+
7
+ # Data Dictionary folders
8
+ /dd
@@ -0,0 +1 @@
1
+ ruby-2.0.0-p0
@@ -0,0 +1,10 @@
1
+ require 'test_helper'
2
+
3
+ class DictionaryTest < Test::Unit::TestCase
4
+ include Spout::Tests
5
+
6
+ # You may add additional tests here
7
+ # test "the truth" do
8
+ # assert true
9
+ # end
10
+ end
@@ -0,0 +1 @@
1
+ require 'spout/tests'
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
data/lib/spout/version.rb CHANGED
@@ -3,7 +3,7 @@ module Spout
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
5
  TINY = 0
6
- BUILD = "pre" # nil, "pre", "rc", "rc2"
6
+ BUILD = "rc" # nil, "pre", "rc", "rc2"
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY, BUILD].compact.join('.')
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spout
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.pre
4
+ version: 0.1.0.rc
5
5
  platform: ruby
6
6
  authors:
7
7
  - Remo Mueller
@@ -80,6 +80,13 @@ files:
80
80
  - lib/spout/application.rb
81
81
  - lib/spout/tasks/engine.rake
82
82
  - lib/spout/tasks.rb
83
+ - lib/spout/templates/Gemfile
84
+ - lib/spout/templates/gitignore
85
+ - lib/spout/templates/Rakefile
86
+ - lib/spout/templates/ruby-version
87
+ - lib/spout/templates/test/dictionary_test.rb
88
+ - lib/spout/templates/test/test_helper.rb
89
+ - lib/spout/templates/travis.yml
83
90
  - lib/spout/tests/domain_existence_validation.rb
84
91
  - lib/spout/tests/json_validation.rb
85
92
  - lib/spout/tests/variable_type_validation.rb