fat_table 0.3.1 → 0.3.3

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: 3cff489c9e921eff2138fb44b260b96d548819b7ee1479f9bf89675f2199c9ea
4
- data.tar.gz: 7ad900e458b8d95baaf8044a4d25e742b1796ae9677d9f667180f034760e8a55
3
+ metadata.gz: d95bf4d370e8c501b679aba77975ee9404940383a0058718d4c906b491ef195d
4
+ data.tar.gz: fc39721ae44a5e656bfb8d6225164aa74cf0bdf21246b1eec4c247572b73bf30
5
5
  SHA512:
6
- metadata.gz: 061ddacf0132d62f7d428f513c7a14277a4668c5a37148f80ef87dc484163ee4c001164e20a854d61761f21d6df025a700171e85c33e4f53c548014d7804b4e2
7
- data.tar.gz: 11351e7a9c73624c4395960c226733b2c1ccaa126f0a0f1c2eee042b83f5adacbcea52e303b8566d5746c16648e202441d5df2216cc818799864600c7ee3bf69
6
+ metadata.gz: a532d371acf8e0a8fe36e83410c646a12125af501638749bf69f6c85fedcabf7eabf6b6edd5579eb0b32df42220cdac2f7ce018447b2734749e735815ac53ff2
7
+ data.tar.gz: 555e412df95d31e035debb960c5dc86bfba4ec5b4c9827ea7ec19ef2458a18b01f54d4c620e69c621800ddb31bde7ab9e4d7034c9c53380ee301322260647c49
data/.travis.yml CHANGED
@@ -18,5 +18,5 @@ rvm:
18
18
  - 2.5
19
19
  - 2.6
20
20
  - 2.7
21
- - ruby-head
21
+ - 3.0
22
22
  - truffleruby
data/fat_table.gemspec CHANGED
@@ -68,16 +68,16 @@ Gem::Specification.new do |spec|
68
68
  spec.add_development_dependency 'pry'
69
69
  spec.add_development_dependency 'pry-byebug'
70
70
  spec.add_development_dependency 'pry-doc'
71
- spec.add_development_dependency 'ruby_jard'
72
71
  spec.add_development_dependency 'rake', '~> 13.0'
73
72
  spec.add_development_dependency 'redcarpet'
73
+ spec.add_development_dependency 'pg'
74
74
  spec.add_development_dependency 'rspec', '~> 3.0'
75
75
  spec.add_development_dependency 'rubocop-rspec'
76
76
  spec.add_development_dependency 'rubocop-performance'
77
77
  spec.add_development_dependency 'simplecov'
78
78
 
79
79
  spec.add_runtime_dependency 'activesupport', '>3.0'
80
- spec.add_runtime_dependency 'fat_core', '>= 4.1'
80
+ spec.add_runtime_dependency 'fat_core', '>= 4.9.0'
81
81
  spec.add_runtime_dependency 'rainbow'
82
82
  spec.add_runtime_dependency 'sequel'
83
83
  spec.add_runtime_dependency 'gem-path'
@@ -139,6 +139,19 @@ module FatTable
139
139
  size - 1
140
140
  end
141
141
 
142
+ # :category: Attributes
143
+
144
+ # Force the column to have String type and then convert all items to
145
+ # strings.
146
+ def force_to_string_type
147
+ # msg = "Can only force an empty column to String type"
148
+ # raise UserError, msg unless empty?
149
+ @type = 'String'
150
+ unless empty?
151
+ @items = items.map(&:to_s)
152
+ end
153
+ end
154
+
142
155
  ##########################################################################
143
156
  # Enumerable
144
157
  ##########################################################################
@@ -494,6 +507,15 @@ module FatTable
494
507
  AMR_DATE_RE = %r{(?<dy>\d\d?)[-/](?<mo>\d\d?)[-/](?<yr>\d\d\d\d)\s*
495
508
  (?<tm>T\d\d:\d\d:\d\d(\+\d\d:\d\d)?)?}x
496
509
 
510
+ # A Date like 'Tue, 01 Nov 2016' or 'Tue 01 Nov 2016' or '01 Nov 2016'.
511
+ # These are emitted by Postgresql, so it makes from_sql constructor
512
+ # possible without special formatting of the dates.
513
+ INV_DATE_RE = %r{((mon|tue|wed|thu|fri|sat|sun)[a-zA-z]*,?)?\s+ # looks like dow
514
+ (?<dy>\d\d?)\s+ # one or two-digit day
515
+ (?<mo_name>[jfmasondJFMASOND][A-Za-z]{2,})\s+ # looks like a month name
516
+ (?<yr>\d\d\d\d) # and a 4-digit year
517
+ }xi
518
+
497
519
  # Convert the val to a DateTime if it is either a DateTime, a Date, a Time, or a
498
520
  # String that can be parsed as a DateTime, otherwise return nil. It only
499
521
  # recognizes strings that contain a something like '2016-01-14' or '2/12/1985'
@@ -503,6 +525,7 @@ module FatTable
503
525
  def convert_to_date_time(val)
504
526
  return val if val.is_a?(DateTime)
505
527
  return val if val.is_a?(Date)
528
+ return val.to_datetime if val.is_a?(Time)
506
529
  begin
507
530
  str = val.to_s.clean
508
531
  return nil if str.blank?
@@ -513,6 +536,10 @@ module FatTable
513
536
  date = DateTime.new(Regexp.last_match[:yr].to_i,
514
537
  Regexp.last_match[:mo].to_i,
515
538
  Regexp.last_match[:dy].to_i)
539
+ elsif str =~ INV_DATE_RE
540
+ mo = Date.mo_name_to_num(last_match[:mo_name])
541
+ date = DateTime.new(Regexp.last_match[:yr].to_i, mo,
542
+ Regexp.last_match[:dy].to_i)
516
543
  else
517
544
  return nil
518
545
  end
@@ -158,7 +158,8 @@ module FatTable
158
158
  raise UserError, msg if FatTable.db.nil?
159
159
 
160
160
  result = Table.new
161
- FatTable.db[query].each do |h|
161
+ rows = FatTable.db[query]
162
+ rows.each do |h|
162
163
  result << h
163
164
  end
164
165
  result
@@ -297,6 +298,8 @@ module FatTable
297
298
  # :category: Attributes
298
299
 
299
300
  # Return the table's Column with the given +key+ as its header.
301
+ # @param key [Symbol] symbol for header of column to return
302
+ # @return [FatTable::Column]
300
303
  def column(key)
301
304
  columns.detect { |c| c.header == key.as_sym }
302
305
  end
@@ -311,6 +314,15 @@ module FatTable
311
314
 
312
315
  # :category: Attributes
313
316
 
317
+ # Set the column type for Column with the given +key+ as a String type,
318
+ # but only if empty. Otherwise, we would have to worry about converting
319
+ # existing items in the column to String. Perhaps that's a TODO.
320
+ def set_column_to_string_type(key)
321
+ column(key).force_to_string_type
322
+ end
323
+
324
+ # :category: Attributes
325
+
314
326
  # Return the array of items of the column with the given header symbol
315
327
  # +key+, or if +key+ is an Integer, return that row at that index. So a
316
328
  # table's rows can be accessed by number, and its columns can be accessed by
@@ -980,6 +992,11 @@ module FatTable
980
992
  #
981
993
  # Any groups present in either Table are eliminated in the output Table. See
982
994
  # the README for examples.
995
+ # @param other [FatTable::Table] table to join with self
996
+ # @param exps [Array<String>, Array<Symbol>] table to join with self
997
+ # @param join_type [Array<String>, Array<Symbol>] type of join :inner, :left, :right, :full, :cross
998
+ # @return [FatTable::Table] result of joining self to other
999
+ #
983
1000
  def join(other, *exps, join_type: :inner)
984
1001
  unless other.is_a?(Table)
985
1002
  raise UserError, 'need other table as first argument to join'
@@ -1274,6 +1291,15 @@ module FatTable
1274
1291
 
1275
1292
  # :category: Constructors
1276
1293
 
1294
+ # Add a group boundary mark at the given row, or at the end of the table
1295
+ # by default.
1296
+ def add_boundary(at_row = nil)
1297
+ row = at_row || (size - 1)
1298
+ @boundaries << row
1299
+ end
1300
+
1301
+ # :category: Constructors
1302
+
1277
1303
  # Add a +row+ represented by a Hash having the headers as keys. If +mark:+
1278
1304
  # is set true, mark this row as a boundary. All tables should be built
1279
1305
  # ultimately using this method as a primitive.
@@ -1283,7 +1309,7 @@ module FatTable
1283
1309
  columns << Column.new(header: k) unless column?(k)
1284
1310
  column(key) << v
1285
1311
  end
1286
- @boundaries << (size - 1) if mark
1312
+ add_boundary if mark
1287
1313
  self
1288
1314
  end
1289
1315
 
@@ -2,5 +2,5 @@
2
2
 
3
3
  module FatTable
4
4
  # The current version of FatTable
5
- VERSION = '0.3.1'
5
+ VERSION = '0.3.3'
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fat_table
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel E. Doherty
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-13 00:00:00.000000000 Z
11
+ date: 2022-01-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -81,35 +81,35 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: ruby_jard
84
+ name: rake
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0'
89
+ version: '13.0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '0'
96
+ version: '13.0'
97
97
  - !ruby/object:Gem::Dependency
98
- name: rake
98
+ name: redcarpet
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - "~>"
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
- version: '13.0'
103
+ version: '0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - "~>"
108
+ - - ">="
109
109
  - !ruby/object:Gem::Version
110
- version: '13.0'
110
+ version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
- name: redcarpet
112
+ name: pg
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - ">="
@@ -198,14 +198,14 @@ dependencies:
198
198
  requirements:
199
199
  - - ">="
200
200
  - !ruby/object:Gem::Version
201
- version: '4.1'
201
+ version: 4.9.0
202
202
  type: :runtime
203
203
  prerelease: false
204
204
  version_requirements: !ruby/object:Gem::Requirement
205
205
  requirements:
206
206
  - - ">="
207
207
  - !ruby/object:Gem::Version
208
- version: '4.1'
208
+ version: 4.9.0
209
209
  - !ruby/object:Gem::Dependency
210
210
  name: rainbow
211
211
  requirement: !ruby/object:Gem::Requirement
@@ -320,7 +320,7 @@ licenses: []
320
320
  metadata:
321
321
  allowed_push_host: https://rubygems.org
322
322
  yard.run: yri
323
- post_install_message:
323
+ post_install_message:
324
324
  rdoc_options: []
325
325
  require_paths:
326
326
  - lib
@@ -335,8 +335,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
335
335
  - !ruby/object:Gem::Version
336
336
  version: '0'
337
337
  requirements: []
338
- rubygems_version: 3.1.2
339
- signing_key:
338
+ rubygems_version: 3.3.3
339
+ signing_key:
340
340
  specification_version: 4
341
341
  summary: Provides tools for working with tables as a data type.
342
342
  test_files: []