stats_package_syntax_file_generator 1.0.6 → 1.1.0

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,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MTAyOGExOTg0NWVjNWRhNjc2N2M1NTkzMzdlY2QwMDc2NzY0NGNlYg==
4
+ NDEwN2YzOWY2ZjdjNDM3ZWQ0OWMwNmExZTgzOGM4NjYyNjI5OGRmMQ==
5
5
  data.tar.gz: !binary |-
6
- MmE4N2Y0N2QxYzRhMDgyYTMxMzg0MTY2OGRjZDY3NjhlYzkyYTFhNA==
6
+ OWY2MDAwNjJkMTRkMjFkODY4MjU2MjFlNDhkYjNiNzdiOTQzYWFjMA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MGZjNTQ4NjlhNTQwNjE1NDlmYTM5MTc2NmViNzc1MTZiODY0YzQyYTllODQx
10
- ODk3ZDE5ZGJjZTk5ZWU0MGVjZmFhZWFhMjc0NjdmNTZiOGQ0MTE2MjViYTY0
11
- NWFjOTEzNzdjNDNjY2JmYjdiMjAxNmFjZWQxMWRiMDI1ZTdjMzg=
9
+ YzdmOTYxNGIzOGYyYzYyMjAwNmMyYzQ4Mzg5NmFmYTQ4OTAyNDVmMTI0ZDA2
10
+ OTUwOTY1YzczMTE1YTI1YzZkNjgyOTQ2YjdiZDU1M2RmODNmY2IxMzEwOTkx
11
+ MTY1OGFiNzJhMzM1NzkxMGU3ODM2MmFkZDE4YzY5MzczZDNhMTk=
12
12
  data.tar.gz: !binary |-
13
- OWIxMjQwNGNlNzY1ODI5MjI0YmFkYWY1ZDQ3MzI3MzVmY2ExMjA0ZjNhMmVk
14
- MmIxNGEwMTZhNjQ1MjcyZTc5YTFhMGE3NGU1YzRiMDA1Yzg0NDUyZGJjODE0
15
- OWU2NjlmN2Y2MWNmMGVlYzRjMzEzNmNhZmJhOTFhYzZhMWMyOWQ=
13
+ MWJkZGMyYTNmY2JiMDBjOWRhNTdjZDgyMzFkYTllNmJiOTVjYzhmNDcyMWE3
14
+ NzNjMDY4MjFmYTQ4YTI4OWM5ZjM0M2Q5N2VkZDIxYzQ0MmQ5MTRiMzU4ZTUy
15
+ NDRmMTk0ZDE5MjllNmNjMzk4Njk2YWE0NGQ0OTFhMjNiZDNmYjU=
data/README CHANGED
@@ -4,7 +4,7 @@ This gem produces statistical package syntax files for fixed-column data files.
4
4
  SPSS
5
5
  Stata
6
6
  Stat/Transfer STS metadata files
7
-
7
+ R (via the ipumsr package which depends on IPUMS DDIs)
8
8
 
9
9
  Metadata can be supplied to the Controller in two general ways:
10
10
 
@@ -89,6 +89,7 @@ Class overview:
89
89
  Maker_SPSS
90
90
  Maker_STATA
91
91
  Maker_STS
92
+ Maker_RDDI
92
93
 
93
94
  - Classes responsible for creating syntax.
94
95
 
@@ -14,6 +14,7 @@ require 'yaml'
14
14
  maker_spss
15
15
  maker_stata
16
16
  maker_sts
17
+ maker_rddi
17
18
  ).each do |f|
18
19
  require File.expand_path(File.join(File.dirname(__FILE__), 'syntax_file', f))
19
20
  end
@@ -6,7 +6,7 @@
6
6
  module SyntaxFile
7
7
  class Controller
8
8
 
9
- VERSION = "1.0.6"
9
+ VERSION = "1.1.0"
10
10
 
11
11
  ATTR = {
12
12
  :project => { :req => false, :rw => 'rw', :def => '', :yaml => true },
@@ -46,7 +46,8 @@ def initialize (args = {})
46
46
  'sas' => '.sas',
47
47
  'spss' => '.sps',
48
48
  'stata' => '.do',
49
- 'sts' => '.sts'
49
+ 'sts' => '.sts',
50
+ 'rddi' => '.R'
50
51
  } if @output_file_ext.nil?
51
52
  @output_formats = [] if @output_formats.nil?
52
53
  @record_types = [] if @record_types.nil?
@@ -106,7 +106,12 @@ def comments_start
106
106
  'NOTE: You need to set the Stata working directory to the path',
107
107
  'where the data file is located.',
108
108
  ] if @syntax_type == 'stata'
109
-
109
+
110
+ return [
111
+ "NOTE: To load data, you must download both the extract's data and the DDI",
112
+ "and also set the working directory to the folder with these files (or change the path below).",
113
+ ] if @syntax_type == 'rddi'
114
+
110
115
  cmd = (@syntax_type == 'sas') ? 'libname' : 'cd'
111
116
  result = [
112
117
  "NOTE: You need to edit the `#{cmd}` command to specify the path to the directory",
@@ -0,0 +1,55 @@
1
+ # This file is part of the Minnesota Population Center's stats_package_syntax_file_generator project.
2
+ # For copyright and licensing information, see the NOTICE and LICENSE files
3
+ # in this project's top-level directory, and also on-line at:
4
+ # https://github.com/mnpopcenter/stats_package_syntax_file_generator
5
+
6
+ module SyntaxFile
7
+ class MakerRDDI < Maker
8
+
9
+ def initialize (sfc, syntax_type)
10
+ super
11
+ end
12
+
13
+ def syntax
14
+ r = [
15
+ comments_start,
16
+ check_pkg,
17
+ syn_df,
18
+ comments_end,
19
+ ]
20
+ r.flatten
21
+ end
22
+
23
+ def comments_start
24
+ convert_to_comments(super)
25
+ end
26
+
27
+ def comments_end
28
+ convert_to_comments(super)
29
+ end
30
+
31
+ def convert_to_comments (lines)
32
+ return [] if lines.empty?
33
+ [
34
+ lines.map { |ln| '# ' + ln },
35
+ blank,
36
+ ].flatten
37
+ end
38
+
39
+ def check_pkg
40
+ [
41
+ 'if (!require("ipumsr")) stop("Reading IPUMS data into R requires the ipumsr package. It can be installed using the following command: install.packages(\'ipumsr\')")',
42
+ ''
43
+ ]
44
+ end
45
+
46
+ def syn_df
47
+ ddi_file = @sfc.data_file_name.chomp[0...-3] + 'xml'
48
+ [
49
+ 'ddi <- read_ipums_ddi(' + q(ddi_file) + ')',
50
+ 'data <- read_ipums_micro(ddi)',
51
+ ]
52
+ end
53
+
54
+ end
55
+ end
@@ -4,7 +4,7 @@ project: ipumsi
4
4
  caller: test
5
5
  data_dir_name: __
6
6
  data_file_name: xx9999a.dat
7
- output_formats: [sas, spss, stata, sts]
7
+ output_formats: [sas, spss, stata, sts, rddi]
8
8
  output_dir_name: __
9
9
  output_file_stem: '%s'
10
10
  output_overwrite: true
@@ -231,7 +231,7 @@ def test_generate_syntax_files
231
231
 
232
232
  # Remove files generated during any previous test.
233
233
  stem = 'testing'
234
- expected_files = %w(do sas sps sts).map { |e| stem + '.' + e }
234
+ expected_files = %w(R do sas sps sts).map { |e| stem + '.' + e }
235
235
  remove_file_from_dir(output_dir, expected_files)
236
236
 
237
237
  msg = 'Make sure the testing output directory is empty.'
@@ -0,0 +1,33 @@
1
+ # This file is part of the Minnesota Population Center's stats_package_syntax_file_generator project.
2
+ # For copyright and licensing information, see the NOTICE and LICENSE files
3
+ # in this project's top-level directory, and also on-line at:
4
+ # https://github.com/mnpopcenter/stats_package_syntax_file_generator
5
+
6
+ require File.expand_path(File.join(File.dirname(__FILE__), 'setup.rb'))
7
+
8
+ module StatsPackageSyntaxFileGeneratorTest
9
+ class MakerRDDI < Test::Unit::TestCase
10
+
11
+ include StatsPackageSyntaxFileGeneratorTestSetup
12
+
13
+ def test_create_maker_rddi
14
+ msg = 'Try to create an object.'
15
+ mk = new_maker('rddi')
16
+ assert_instance_of SyntaxFile::MakerRDDI, mk, msg
17
+ end
18
+
19
+ def test_check_pkg
20
+ msg = 'Compare against hardcoded result.'
21
+ mk = new_maker('rddi')
22
+ expected = [
23
+ 'if (!require("ipumsr")) stop("Reading IPUMS data into R requires the ipumsr package. It can be installed using the following command: install.packages(\'ipumsr\')")',
24
+ ''
25
+ ]
26
+ actual = mk.check_pkg
27
+ assert_equal expected, actual, msg
28
+ end
29
+
30
+
31
+
32
+ end
33
+ end
data/tests/ts_all.rb CHANGED
@@ -15,6 +15,7 @@ require 'test/unit'
15
15
  tc_maker_spss
16
16
  tc_maker_stata
17
17
  tc_maker_sts
18
+ tc_maker_rddi
18
19
  ).each do |f|
19
20
  require File.expand_path(File.join(File.dirname(__FILE__), f))
20
21
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stats_package_syntax_file_generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Monty Hindman, Marcus Peterson, Colin Davis, Dan Elbert, Jayandra Pokharel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-30 00:00:00.000000000 Z
11
+ date: 2018-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -64,6 +64,7 @@ files:
64
64
  - lib/stats_package_syntax_file_generator.rb
65
65
  - lib/syntax_file/controller.rb
66
66
  - lib/syntax_file/maker.rb
67
+ - lib/syntax_file/maker_rddi.rb
67
68
  - lib/syntax_file/maker_sas.rb
68
69
  - lib/syntax_file/maker_spss.rb
69
70
  - lib/syntax_file/maker_stata.rb
@@ -75,6 +76,7 @@ files:
75
76
  - tests/setup.rb
76
77
  - tests/tc_controller.rb
77
78
  - tests/tc_maker.rb
79
+ - tests/tc_maker_rddi.rb
78
80
  - tests/tc_maker_sas.rb
79
81
  - tests/tc_maker_spss.rb
80
82
  - tests/tc_maker_stata.rb