ruby_px 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -2
- data/CHANGELOG.md +10 -0
- data/Gemfile +2 -0
- data/README.md +1 -0
- data/Rakefile +5 -3
- data/bin/console +4 -3
- data/lib/ruby_px.rb +2 -0
- data/lib/ruby_px/dataset.rb +34 -35
- data/ruby_px.gemspec +19 -18
- metadata +15 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cfa0ddb5f455e289afe1507164ab005e0896e7e091531a052472f36cfdfe11d3
|
4
|
+
data.tar.gz: 3acf6d18b2ae29ddceab2c0859d4fe79be33a61a54be7f93632a014ebaf5dee7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2439c7a3698ae78f288866cb91933325dbd48ec88a2bbc6b54353e6fe4567e768b7a2c6febb326c2e6566f1f4633eca4b6bb4d7e5ea471dacae21dbe6818f66
|
7
|
+
data.tar.gz: 5482d50e2be5fc9fc4ab6c1b2d40bdf7e2b4b1ea8f2f528ef13d2c575cd9630208ff6e188ba3e3e8c3f17eb4e005787c7c64095c4619d77b0ed23125a5865d80
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# CHANGELOG
|
2
|
+
|
3
|
+
## 0.6.0 (2020-04-28)
|
4
|
+
|
5
|
+
- Nice badge with the current version
|
6
|
+
- Added Changelog!
|
7
|
+
- Updated dependencies
|
8
|
+
- Fix multilingual VALUES and equals signs in values [#7](https://github.com/PopulateTools/ruby_px/pull/7)
|
9
|
+
- Use Rubocop to check syntax
|
10
|
+
|
data/Gemfile
CHANGED
data/README.md
CHANGED
data/Rakefile
CHANGED
data/bin/console
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
require
|
4
|
-
require_relative
|
4
|
+
require 'bundler/setup'
|
5
|
+
require_relative '../lib/ruby_px'
|
5
6
|
|
6
7
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
8
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +11,5 @@ require_relative "../lib/ruby_px"
|
|
10
11
|
# require "pry"
|
11
12
|
# Pry.start
|
12
13
|
|
13
|
-
require
|
14
|
+
require 'irb'
|
14
15
|
IRB.start
|
data/lib/ruby_px.rb
CHANGED
data/lib/ruby_px/dataset.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'open-uri'
|
2
4
|
|
3
5
|
module RubyPx
|
4
6
|
class Dataset
|
5
7
|
attr_reader :headings, :stubs
|
6
8
|
|
7
|
-
METADATA_RECORDS = [
|
9
|
+
METADATA_RECORDS = %w[TITLE UNITS SOURCE CONTACT LAST-UPDATED CREATION-DATE].freeze
|
8
10
|
HEADING_RECORD = 'HEADING'
|
9
11
|
STUB_RECORD = 'STUB'
|
10
12
|
|
@@ -52,8 +54,10 @@ module RubyPx
|
|
52
54
|
|
53
55
|
def data(options)
|
54
56
|
# Validate parameters
|
55
|
-
options.each do |k,v|
|
56
|
-
|
57
|
+
options.each do |k, v|
|
58
|
+
unless dimension(k).include?(v)
|
59
|
+
raise "Invalid value #{v} for dimension #{k}"
|
60
|
+
end
|
57
61
|
end
|
58
62
|
|
59
63
|
# Return a single value
|
@@ -65,20 +69,20 @@ module RubyPx
|
|
65
69
|
|
66
70
|
# positions are i, j, k
|
67
71
|
positions = (stubs + headings).map do |dimension_name|
|
68
|
-
|
72
|
+
dimension(dimension_name).index(options[dimension_name])
|
69
73
|
end
|
70
74
|
|
71
75
|
# dimension_sizes are from all dimensions except the first one
|
72
76
|
dimension_sizes = (stubs + headings)[1..-1].map do |dimension_name|
|
73
|
-
|
77
|
+
dimension(dimension_name).length
|
74
78
|
end
|
75
79
|
|
76
80
|
positions.each_with_index do |p, i|
|
77
81
|
d = dimension_sizes[i..-1].reduce(&:*)
|
78
|
-
offset += (d ? p*d : p)
|
82
|
+
offset += (d ? p * d : p)
|
79
83
|
end
|
80
84
|
|
81
|
-
|
85
|
+
@data[offset]
|
82
86
|
|
83
87
|
# Return an array of options
|
84
88
|
elsif options.length == dimensions.length - 1
|
@@ -89,14 +93,14 @@ module RubyPx
|
|
89
93
|
result << data(options.merge(missing_dimension => dimension_value))
|
90
94
|
end
|
91
95
|
|
92
|
-
|
96
|
+
result
|
93
97
|
else
|
94
|
-
raise
|
98
|
+
raise 'Not implented yet, sorry'
|
95
99
|
end
|
96
100
|
end
|
97
101
|
|
98
102
|
def inspect
|
99
|
-
"#<#{self.class.name}:#{
|
103
|
+
"#<#{self.class.name}:#{object_id}>"
|
100
104
|
end
|
101
105
|
|
102
106
|
private
|
@@ -113,7 +117,7 @@ module RubyPx
|
|
113
117
|
@line = line.force_encoding('utf-8').encode('utf-8')
|
114
118
|
|
115
119
|
if @current_record.nil?
|
116
|
-
key, value = line.
|
120
|
+
key, value = line.split('=', 2)
|
117
121
|
set_current_record(key)
|
118
122
|
else
|
119
123
|
value = line
|
@@ -122,27 +126,25 @@ module RubyPx
|
|
122
126
|
return if @current_record.nil? || value.nil?
|
123
127
|
|
124
128
|
if @type == :data
|
125
|
-
value = value.split(/[\ ;,\t]/).delete_if
|
129
|
+
value = value.split(/[\ ;,\t]/).delete_if(&:blank?).each(&:strip)
|
126
130
|
|
127
|
-
add_value_to_bucket(bucket,value) unless value == [';']
|
131
|
+
add_value_to_bucket(bucket, value) unless value == [';']
|
128
132
|
else
|
129
133
|
# First format: "\"20141201\";"
|
130
134
|
if value =~ /\A\"([^"]+)\";\z/
|
131
135
|
value = value.match(/\A\"([^"]+)\";\z/)[1]
|
132
136
|
add_value_to_bucket(bucket, value.strip)
|
133
137
|
|
134
|
-
|
138
|
+
# Second format: "Ambos sexos","Hombres","Mujeres";
|
135
139
|
elsif value =~ /\"([^"]+)\",?/
|
136
|
-
value = value.split(/\"([^"]+)\",?;?/).delete_if
|
140
|
+
value = value.split(/\"([^"]+)\",?;?/).delete_if(&:blank?).each(&:strip)
|
137
141
|
add_value_to_bucket(bucket, value)
|
138
142
|
end
|
139
143
|
end
|
140
144
|
|
141
145
|
# If we see a ; at the end of the line, close out the record so we
|
142
146
|
# expect a new record.
|
143
|
-
if line[-1..-1] ==
|
144
|
-
@current_record = nil
|
145
|
-
end
|
147
|
+
@current_record = nil if line[-1..-1] == ';'
|
146
148
|
end
|
147
149
|
|
148
150
|
def set_current_record(key)
|
@@ -155,7 +157,7 @@ module RubyPx
|
|
155
157
|
elsif key == STUB_RECORD
|
156
158
|
@type = :stubs
|
157
159
|
key
|
158
|
-
elsif key =~ /\AVALUES/
|
160
|
+
elsif key =~ /\AVALUES/ && key !~ /\[\w\w\]/
|
159
161
|
@type = :values
|
160
162
|
key.match(/\"([^"]+)\"/)[1]
|
161
163
|
elsif key =~ /\ADATA/
|
@@ -174,23 +176,20 @@ module RubyPx
|
|
174
176
|
elsif @type == :headings || @type == :stubs
|
175
177
|
bucket << value
|
176
178
|
bucket.flatten!
|
177
|
-
|
178
|
-
if
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
if
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
bucket[@current_record].flatten!
|
190
|
-
end
|
179
|
+
elsif bucket.is_a?(Hash)
|
180
|
+
if value.is_a?(Array)
|
181
|
+
value = value.map(&:strip)
|
182
|
+
elsif value.is_a?(String)
|
183
|
+
value.strip!
|
184
|
+
end
|
185
|
+
if bucket[@current_record].nil?
|
186
|
+
value = Array.wrap(value) if @type == :values
|
187
|
+
bucket[@current_record] = value
|
188
|
+
else
|
189
|
+
bucket[@current_record].concat([value])
|
190
|
+
bucket[@current_record].flatten!
|
191
191
|
end
|
192
192
|
end
|
193
193
|
end
|
194
|
-
|
195
194
|
end
|
196
195
|
end
|
data/ruby_px.gemspec
CHANGED
@@ -1,34 +1,35 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
|
5
6
|
Gem::Specification.new do |spec|
|
6
|
-
spec.name =
|
7
|
-
spec.version = '0.
|
8
|
-
spec.authors = [
|
9
|
-
spec.email = [
|
7
|
+
spec.name = 'ruby_px'
|
8
|
+
spec.version = '0.6.0'
|
9
|
+
spec.authors = ['Fernando Blat']
|
10
|
+
spec.email = ['fernando@blat.es']
|
10
11
|
|
11
|
-
spec.summary =
|
12
|
-
spec.description =
|
13
|
-
spec.homepage =
|
14
|
-
spec.license =
|
12
|
+
spec.summary = 'Read PC-Axis files using Ruby'
|
13
|
+
spec.description = 'Read PC-Axis files using Ruby'
|
14
|
+
spec.homepage = 'https://github.com/PopulateTools/ruby_px'
|
15
|
+
spec.license = 'MIT'
|
15
16
|
|
16
17
|
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
17
18
|
# delete this section to allow pushing this gem to any host.
|
18
19
|
if spec.respond_to?(:metadata)
|
19
|
-
spec.metadata['allowed_push_host'] =
|
20
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
20
21
|
else
|
21
|
-
raise
|
22
|
+
raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
|
22
23
|
end
|
23
24
|
|
24
25
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
-
spec.bindir =
|
26
|
+
spec.bindir = 'exe'
|
26
27
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
-
spec.require_paths = [
|
28
|
+
spec.require_paths = ['lib']
|
28
29
|
|
29
|
-
spec.add_runtime_dependency
|
30
|
+
spec.add_runtime_dependency 'activesupport', '>= 6.0'
|
30
31
|
|
31
|
-
spec.add_development_dependency
|
32
|
-
spec.add_development_dependency
|
33
|
-
spec.add_development_dependency
|
32
|
+
spec.add_development_dependency 'bundler'
|
33
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
34
|
+
spec.add_development_dependency 'rspec', '~> 3.9'
|
34
35
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_px
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fernando Blat
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -16,59 +16,59 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: '6.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: '6.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '13.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '13.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '3.
|
61
|
+
version: '3.9'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '3.
|
68
|
+
version: '3.9'
|
69
69
|
description: Read PC-Axis files using Ruby
|
70
70
|
email:
|
71
|
-
-
|
71
|
+
- fernando@blat.es
|
72
72
|
executables: []
|
73
73
|
extensions: []
|
74
74
|
extra_rdoc_files: []
|
@@ -76,6 +76,7 @@ files:
|
|
76
76
|
- ".gitignore"
|
77
77
|
- ".rspec"
|
78
78
|
- ".travis.yml"
|
79
|
+
- CHANGELOG.md
|
79
80
|
- CODE_OF_CONDUCT.md
|
80
81
|
- Gemfile
|
81
82
|
- LICENSE.txt
|
@@ -106,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
107
|
- !ruby/object:Gem::Version
|
107
108
|
version: '0'
|
108
109
|
requirements: []
|
109
|
-
rubygems_version: 3.
|
110
|
+
rubygems_version: 3.1.2
|
110
111
|
signing_key:
|
111
112
|
specification_version: 4
|
112
113
|
summary: Read PC-Axis files using Ruby
|