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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 01235f74e28d6d1186e62da5c6707ddac25e6f50778b6e0c6e7e7a73ceeecf36
4
- data.tar.gz: 960319e79d1b648e652f1fa5d485384e100155a20f6cc97a12565687dbcbc4f4
3
+ metadata.gz: cfa0ddb5f455e289afe1507164ab005e0896e7e091531a052472f36cfdfe11d3
4
+ data.tar.gz: 3acf6d18b2ae29ddceab2c0859d4fe79be33a61a54be7f93632a014ebaf5dee7
5
5
  SHA512:
6
- metadata.gz: e559e8c337c98de95d64d49ad15873f48dec23dda11c63082f9f03b901db1357397bb4d4e1f82b0e804cf2bc42869823941de97c4525338b5f7b21aa4eb85433
7
- data.tar.gz: 9db728337171b243da96e49a0c4f7a4852494a1743154637e98321698a31ee72765d2477be6b7774829cecb9a5fd82508366668878fda94686b7ef107956f886
6
+ metadata.gz: c2439c7a3698ae78f288866cb91933325dbd48ec88a2bbc6b54353e6fe4567e768b7a2c6febb326c2e6566f1f4633eca4b6bb4d7e5ea471dacae21dbe6818f66
7
+ data.tar.gz: 5482d50e2be5fc9fc4ab6c1b2d40bdf7e2b4b1ea8f2f528ef13d2c575cd9630208ff6e188ba3e3e8c3f17eb4e005787c7c64095c4619d77b0ed23125a5865d80
@@ -1,4 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2.3
4
- before_install: gem install bundler -v 1.10.6
3
+ - 2.7.1
4
+ - 2.6.3
5
+ before_install: gem install bundler
@@ -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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in ruby_px.gemspec
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # RubyPx
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/ruby_px.svg)](https://badge.fury.io/rb/ruby_px)
3
4
  [![Build Status](https://travis-ci.org/PopulateTools/ruby_px.svg?branch=master)](https://travis-ci.org/PopulateTools/ruby_px)
4
5
 
5
6
  Work with PC-Axis files using Ruby.
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
3
5
 
4
6
  RSpec::Core::RakeTask.new(:spec)
5
7
 
6
- task :default => :spec
8
+ task default: :spec
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- require "bundler/setup"
4
- require_relative "../lib/ruby_px"
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 "irb"
14
+ require 'irb'
14
15
  IRB.start
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'active_support/all'
2
4
 
3
5
  module RubyPx
@@ -1,10 +1,12 @@
1
- require "open-uri"
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 = ['TITLE','UNITS','SOURCE','CONTACT','LAST-UPDATED','CREATION-DATE']
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
- raise "Invalid value #{v} for dimension #{k}" unless dimension(k).include?(v)
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
- self.dimension(dimension_name).index(options[dimension_name])
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
- self.dimension(dimension_name).length
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
- return @data[offset]
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
- return result
96
+ result
93
97
  else
94
- raise "Not implented yet, sorry"
98
+ raise 'Not implented yet, sorry'
95
99
  end
96
100
  end
97
101
 
98
102
  def inspect
99
- "#<#{self.class.name}:#{self.object_id}>"
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.scan(/[^\=]+/)
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{ |s| s.blank? }.each(&:strip)
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
- # Second format: "Ambos sexos","Hombres","Mujeres";
138
+ # Second format: "Ambos sexos","Hombres","Mujeres";
135
139
  elsif value =~ /\"([^"]+)\",?/
136
- value = value.split(/\"([^"]+)\",?;?/).delete_if{ |s| s.blank? }.each(&:strip)
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
- else
178
- if bucket.is_a?(Hash)
179
- if value.is_a?(Array)
180
- value = value.map(&:strip)
181
- elsif value.is_a?(String)
182
- value.strip!
183
- end
184
- if bucket[@current_record].nil?
185
- value = Array.wrap(value) if @type == :values
186
- bucket[@current_record] = value
187
- else
188
- bucket[@current_record].concat([value])
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
@@ -1,34 +1,35 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
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 = "ruby_px"
7
- spec.version = '0.5.0'
8
- spec.authors = ["Fernando Blat"]
9
- spec.email = ["ferblape@gmail.com"]
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 = %q{Read PC-Axis files using Ruby}
12
- spec.description = %q{Read PC-Axis files using Ruby}
13
- spec.homepage = "https://github.com/PopulateTools/ruby_px"
14
- spec.license = "MIT"
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'] = "https://rubygems.org"
20
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
20
21
  else
21
- raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
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 = "exe"
26
+ spec.bindir = 'exe'
26
27
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
- spec.require_paths = ["lib"]
28
+ spec.require_paths = ['lib']
28
29
 
29
- spec.add_runtime_dependency "activesupport", ">= 4.2.5"
30
+ spec.add_runtime_dependency 'activesupport', '>= 6.0'
30
31
 
31
- spec.add_development_dependency "bundler", "~> 2.0.1"
32
- spec.add_development_dependency "rake", "~> 12.3"
33
- spec.add_development_dependency "rspec", "~> 3.8"
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.5.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: 2019-02-14 00:00:00.000000000 Z
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: 4.2.5
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: 4.2.5
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: 2.0.1
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: 2.0.1
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: '12.3'
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: '12.3'
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.8'
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.8'
68
+ version: '3.9'
69
69
  description: Read PC-Axis files using Ruby
70
70
  email:
71
- - ferblape@gmail.com
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.0.2
110
+ rubygems_version: 3.1.2
110
111
  signing_key:
111
112
  specification_version: 4
112
113
  summary: Read PC-Axis files using Ruby