Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
ruby: ['2.7', '3.0', '3.1', '3.2']
ruby: ['3.2', '3.3']
include:
- os: ubuntu-latest
ruby: '3.2'
ruby: '3.3'
coverage: true
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -41,7 +41,7 @@ jobs:
COVERAGE: ${{ matrix.coverage }}
- name: Generate coverage artifact
if: ${{ matrix.coverage }}
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: docs-coverage
path: docs/coverage
Expand All @@ -50,7 +50,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
Expand All @@ -59,7 +59,7 @@ jobs:
- name: Generate Ruby API documentation
run : bundle exec yard doc
- name: Generate Ruby API documentation artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: docs-ruby
path: docs/ruby
Expand All @@ -80,12 +80,12 @@ jobs:
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Fetch Ruby API documentation artifact
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: docs-ruby
path: docs/ruby
- name: Fetch coverage artifact
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: docs-coverage
path: docs/coverage
Expand Down
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require:
- rubocop-rspec

AllCops:
TargetRubyVersion: 2.7
TargetRubyVersion: 3.2
NewCops: enable
Exclude:
- bin/rspec
Expand Down
10 changes: 7 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@ GEM
docile (1.4.0)
json (2.6.3)
language_server-protocol (3.17.0.3)
nokogiri (1.15.4-x86_64-darwin)
nokogiri (1.18.8-arm64-darwin)
racc (~> 1.4)
nokogiri (1.15.4-x86_64-linux)
nokogiri (1.18.8-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.18.8-x86_64-linux-gnu)
racc (~> 1.4)
parallel (1.23.0)
parser (3.2.2.3)
ast (~> 2.4.1)
racc
racc (1.7.1)
racc (1.8.1)
rainbow (3.1.1)
regexp_parser (2.8.1)
rexml (3.2.6)
Expand Down Expand Up @@ -77,6 +79,8 @@ GEM
yard (0.9.34)

PLATFORMS
arm64-darwin-23
arm64-darwin-24
x86_64-darwin
x86_64-linux

Expand Down
10 changes: 5 additions & 5 deletions lib/sheetah/attribute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ def each_column(config)
header, header_pattern = config.header(key, index)

yield Column.new(
key: key,
key:,
type: compiled_type,
index: index,
header: header,
header_pattern: header_pattern,
required: required
index:,
header:,
header_pattern:,
required:
)
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/sheetah/backends.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ module Backends
class << self
attr_reader :registry

def open(*args, **opts, &block)
backend = opts.delete(:backend) || registry.get(*args, **opts)
def open(*, **opts, &)
backend = opts.delete(:backend) || registry.get(*, **opts)

if backend.nil?
return Utils::MonadicResult::Failure.new(SimpleError.new("no_applicable_backend"))
end

backend.open(*args, **opts, &block)
backend.open(*, **opts, &)
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/sheetah/backends/csv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def each_header
@headers.each_with_index do |header, col_idx|
col = Sheet.int2col(col_idx + 1)

yield Header.new(col: col, value: header)
yield Header.new(col:, value: header)
end

self
Expand All @@ -72,10 +72,10 @@ def each_row
value = Array.new(@cols_count) do |col_idx|
col = Sheet.int2col(col_idx + 1)

Cell.new(row: row, col: col, value: raw[col_idx])
Cell.new(row:, col:, value: raw[col_idx])
end

yield Row.new(row: row, value: value)
yield Row.new(row:, value:)
end

self
Expand Down
4 changes: 2 additions & 2 deletions lib/sheetah/backends/wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ def each_row
raw = @table[row]

value = Array.new(@cols_count) do |col_idx|
Cell.new(row: row, col: Sheet.int2col(col_idx + 1), value: raw[col_idx])
Cell.new(row:, col: Sheet.int2col(col_idx + 1), value: raw[col_idx])
end

yield Row.new(row: row, value: value)
yield Row.new(row:, value:)
end

self
Expand Down
6 changes: 3 additions & 3 deletions lib/sheetah/backends/xlsx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def each_header
@headers.each_with_index do |header, col_idx|
col = Sheet.int2col(col_idx + 1)

yield Header.new(col: col, value: header)
yield Header.new(col:, value: header)
end

self
Expand All @@ -63,10 +63,10 @@ def each_row
value = Array.new(@cols_count) do |col_idx|
col = Sheet.int2col(col_idx + 1)

Cell.new(row: row, col: col, value: raw[col_idx])
Cell.new(row:, col:, value: raw[col_idx])
end

yield Row.new(row: row, value: value)
yield Row.new(row:, value:)
end

self
Expand Down
4 changes: 2 additions & 2 deletions lib/sheetah/headers.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require "set"

module Sheetah
class Headers
include Utils::MonadicResult
Expand Down Expand Up @@ -72,6 +70,8 @@ def add_ensure_column_is_specified(header, column)
@messenger.error("invalid_header", header.value)
end

@messenger.warn("ignored_column", header.value) if @specification.report_ignored_columns?

false
end

Expand Down
12 changes: 6 additions & 6 deletions lib/sheetah/messaging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def scoping(...)
dup.scoping!(...)
end

def scope_row!(row, &block)
def scope_row!(row, &)
scope = case @scope
when SCOPES::COL, SCOPES::CELL
SCOPES::CELL
Expand All @@ -118,10 +118,10 @@ def scope_row!(row, &block)
scope_data = @scope_data.dup || {}
scope_data[:row] = row

scoping!(scope, scope_data, &block)
scoping!(scope, scope_data, &)
end

def scope_col!(col, &block)
def scope_col!(col, &)
scope = case @scope
when SCOPES::ROW, SCOPES::CELL
SCOPES::CELL
Expand All @@ -132,7 +132,7 @@ def scope_col!(col, &block)
scope_data = @scope_data.dup || {}
scope_data[:col] = col

scoping!(scope, scope_data, &block)
scoping!(scope, scope_data, &)
end

def scope_row(...)
Expand All @@ -159,11 +159,11 @@ def exception(error)

def add(severity, code, data)
messages << Message.new(
code: code,
code:,
code_data: data,
scope: @scope,
scope_data: @scope_data,
severity: severity
severity:
)

self
Expand Down
1 change: 0 additions & 1 deletion lib/sheetah/row_value_builder.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# frozen_string_literal: true

require "set"
require_relative "utils/monadic_result"

module Sheetah
Expand Down
4 changes: 2 additions & 2 deletions lib/sheetah/sheet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ def self.int2col(...)
end

module ClassMethods
def open(*args, **opts)
def open(*, **)
handle_sheet_error do
sheet = new(*args, **opts)
sheet = new(*, **)
next sheet unless block_given?

begin
Expand Down
8 changes: 4 additions & 4 deletions lib/sheetah/sheet_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ def initialize(specification)
@specification = specification
end

def call(*args, **opts)
def call(*, **)
messenger = Messaging::Messenger.new

result = Do() do
Backends.open(*args, **opts) do |sheet|
Backends.open(*, **) do |sheet|
row_processor = build_row_processor(sheet, messenger)

sheet.each_row do |row|
Expand All @@ -35,7 +35,7 @@ def call(*args, **opts)
private

def parse_headers(sheet, messenger)
headers = Headers.new(specification: @specification, messenger: messenger)
headers = Headers.new(specification: @specification, messenger:)

sheet.each_header do |header|
headers.add(header)
Expand All @@ -47,7 +47,7 @@ def parse_headers(sheet, messenger)
def build_row_processor(sheet, messenger)
headers = parse_headers(sheet, messenger).unwrap

RowProcessor.new(headers: headers, messenger: messenger)
RowProcessor.new(headers:, messenger:)
end

def handle_result(result, messenger)
Expand Down
7 changes: 6 additions & 1 deletion lib/sheetah/specification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ class MutablePatternError < Errors::SpecError
class DuplicatedPatternError < Errors::SpecError
end

def initialize(ignore_unspecified_columns: false)
def initialize(ignore_unspecified_columns: false, report_ignored_columns: false)
@column_by_pattern = {}
@ignore_unspecified_columns = ignore_unspecified_columns
@report_ignored_columns = report_ignored_columns
end

def set(pattern, column)
Expand Down Expand Up @@ -56,6 +57,10 @@ def ignore_unspecified_columns?
@ignore_unspecified_columns
end

def report_ignored_columns?
@report_ignored_columns
end

def freeze
@column_by_pattern.freeze
super
Expand Down
9 changes: 6 additions & 3 deletions lib/sheetah/template.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# frozen_string_literal: true

require "set"
require_relative "attribute"
require_relative "specification"
require_relative "errors/spec_error"
Expand All @@ -26,13 +25,17 @@ module Sheetah
# specification, and composite attributes will produce as many columns as
# required by the number of scalar values they hold.
class Template
def initialize(attributes:, ignore_unspecified_columns: false)
def initialize(attributes:, ignore_unspecified_columns: false, report_ignored_columns: false)
@attributes = build_attributes(attributes)
@ignore_unspecified_columns = ignore_unspecified_columns
@report_ignored_columns = ignore_unspecified_columns && report_ignored_columns
end

def apply(config)
specification = Specification.new(ignore_unspecified_columns: @ignore_unspecified_columns)
specification = Specification.new(
ignore_unspecified_columns: @ignore_unspecified_columns,
report_ignored_columns: @report_ignored_columns
)

@attributes.each do |attribute|
attribute.each_column(config) do |column|
Expand Down
4 changes: 2 additions & 2 deletions lib/sheetah/types/type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ def new!(...)

self.cast_classes = []

def initialize(**opts)
def initialize(**)
@cast_chain = CastChain.new

self.class.cast_classes.each do |cast_class|
@cast_chain.append(cast_class.new(**opts))
@cast_chain.append(cast_class.new(**))
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/sheetah/utils/cell_string_cleaner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ module Sheetah
module Utils
class CellStringCleaner
garbage = "(?:[^[:print:]]|[[:space:]])+"
GARBAGE_PREFIX = /\A#{garbage}/.freeze
GARBAGE_SUFFIX = /#{garbage}\Z/.freeze
GARBAGE_PREFIX = /\A#{garbage}/
GARBAGE_SUFFIX = /#{garbage}\Z/
private_constant :GARBAGE_PREFIX, :GARBAGE_SUFFIX

def self.call(...)
Expand Down
4 changes: 2 additions & 2 deletions lib/sheetah/utils/monadic_result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ def Failure(...)
Failure.new(...)
end

def Do(&block)
catch(DO_TOKEN, &block)
def Do(&)
catch(DO_TOKEN, &)
end

# rubocop:enable Naming/MethodName
Expand Down
2 changes: 1 addition & 1 deletion sheetah.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
spec.homepage = "https://steeple.com"
spec.summary = "Process tabular data from different sources with a rich, unified API"

spec.required_ruby_version = ">= 2.7.0"
spec.required_ruby_version = ">= 3.2"

spec.metadata["homepage_uri"] = "https://github.com/steeple-org/sheetah"
spec.metadata["source_code_uri"] = "https://github.com/steeple-org/sheetah"
Expand Down
Loading