tc211-termbase 0.1.7 → 0.1.8

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: 96e9ae479fc780b5643eb78d4ea9b716ef297dcb3cdbaa329a7f3994e76a4b9c
4
- data.tar.gz: 5ae853f863b8ffc90e1485343ed17690155182c5d0a4958b24ce760f1e019baa
3
+ metadata.gz: '049c87340f58462f36a45c0978834fa683de647e72af78a55c2d555fc7ea09aa'
4
+ data.tar.gz: 2b2c751263666da6a923c23e806b6c40cac19e341302d0de2a61033b53362894
5
5
  SHA512:
6
- metadata.gz: 9b46dc13a7ef20b1efae6398470c75c43cee81c38048c0d16fa52df9bf34b840dfaebdb92b1919f258e2364e012cbd6705dfda1e7ec735414cfc493c5ec89c83
7
- data.tar.gz: 742bf51d592fa2661a7b610c58a423ba97dea3fa8a03b1b658017d985e29dcf6bf6465ab9058872e991e7c816dade89d93f2137d36c84c971cd438dbfc77d98b
6
+ metadata.gz: a2a74af7f537f2220380174f965fa83f3daedc837d19796c831ad7dcf4125cb3b654dfa9be6e2e8505e70431e0c2739efd2f148fae918506806aab26f79bda67
7
+ data.tar.gz: ebc860160347076c9a14f1caaef7172e06a5c686d80524b18325ef23fd98782b2135f6643d60d0d9447ee9ff9757e50ec8b8acc961ebbd28178e50b6193863b0
data/Gemfile CHANGED
@@ -2,5 +2,8 @@ source "https://rubygems.org"
2
2
 
3
3
  git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
4
 
5
+ # gem "pry"
6
+ # gem "pry-coolline"
7
+
5
8
  # Specify your gem's dependencies in tc211-termbase.gemspec
6
9
  gemspec
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tc211-termbase (0.1.7)
4
+ tc211-termbase (0.1.8)
5
5
  creek
6
6
  iso-639
7
7
  relaton (~> 0.5)
@@ -90,7 +90,16 @@ module Tc211::Termbase
90
90
  end
91
91
 
92
92
  def structure
93
- @structure ||= @header_row.inject({}) do |acc, (key, value)|
93
+ return @structure if @structure
94
+
95
+ header_mapping = parse_header_mapping
96
+ validate_header_mapping(header_mapping)
97
+
98
+ @structure = header_mapping
99
+ end
100
+
101
+ def parse_header_mapping
102
+ @header_row.inject({}) do |acc, (key, value)|
94
103
  # puts "#{key}, #{value}, #{GLOSSARY_HEADER_TITLES[value]}"
95
104
 
96
105
  # convert whitespace to a single space
@@ -119,9 +128,20 @@ module Tc211::Termbase
119
128
  end
120
129
 
121
130
  end
131
+ end
132
+
133
+ class HeaderMappingInvalidError < StandardError; end;
122
134
 
123
- # puts "============ structure is: #{@structure.inspect}"
124
- @structure
135
+ # Validate structure
136
+ # - should not have multiple columns mapping to the same key
137
+ def validate_header_mapping(header_mapping)
138
+ header_mapping.group_by do |k, v|
139
+ v
140
+ end.each do |k, v|
141
+ if v.length > 1
142
+ raise HeaderMappingInvalidError.new("Data key '#{k}' mapping from columns #{v.map(&:first)}; it should only be mapped from one column. Please check the TERM_BODY_COLUMN_MAP constant.")
143
+ end
144
+ end
125
145
  end
126
146
 
127
147
  def self.match_header(columns)
@@ -1,5 +1,5 @@
1
1
  module Tc211
2
2
  module Termbase
3
- VERSION = "0.1.7"
3
+ VERSION = "0.1.8"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tc211-termbase
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose