Skip to content

Commit

Permalink
v4 revision: Bumped Ruby version and all dependencies (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
svyatov authored Jul 9, 2024
1 parent 5a32111 commit 955de77
Show file tree
Hide file tree
Showing 18 changed files with 163 additions and 129 deletions.
27 changes: 9 additions & 18 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file

version: 2
updates:
- package-ecosystem: bundler
directory: "/"
schedule:
interval: daily
time: "02:00"
open-pull-requests-limit: 15
allow:
- dependency-type: direct
- dependency-type: indirect
ignore:
- dependency-name: rubocop
versions:
- 1.10.0
- 1.11.0
- 1.12.0
- 1.12.1
- 1.9.0
- 1.9.1
- package-ecosystem: "bundler" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
39 changes: 39 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: CI

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

on:
push:
branches: ["main"]
pull_request:
branches: ["main"]

jobs:
build:
runs-on: ubuntu-latest
name: Ruby ${{ matrix.ruby_version }}
strategy:
matrix:
ruby_version: [ruby-head, '3.3', '3.2', '3.1']

env:
COVERAGE: true
CC_TEST_REPORTER_ID: ${{ vars.CC_TEST_REPORTER_ID }}

steps:
- uses: actions/checkout@v4

- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby_version }}
bundler-cache: true
continue-on-error: ${{ matrix.ruby_version == 'ruby-head' }}

- run: bundle exec rake
continue-on-error: ${{ matrix.ruby_version == 'ruby-head' }}

- uses: paambaati/[email protected]
# Only upload coverage for the latest Ruby
if: ${{ matrix.ruby_version == '3.3' }}
8 changes: 7 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ require:
- rubocop-rspec

AllCops:
TargetRubyVersion: 2.5
TargetRubyVersion: 3.1
DisplayCopNames: true
DisplayStyleGuide: true
ExtraDetails: true
SuggestExtensions: false
NewCops: enable

Layout/LineLength:
Max: 120
Expand All @@ -26,6 +28,10 @@ Metrics/BlockLength:
Exclude:
- 'spec/**/*'

Lint/MissingSuper:
AllowedParentClasses:
- Base

RSpec/MultipleExpectations:
Max: 5

Expand Down
32 changes: 0 additions & 32 deletions .travis.yml

This file was deleted.

14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Changelog

## [4.0.0] - 2024-07-09

### Breaking changes

- Minimum required Ruby version is 3.1 now
- Default repository branch renamed to `main`

### Updated

- Small internal refactorings
- TravisCI -> GitHub Actions
- Dropped tests for Ruby below 3.1
- Rubocop's Ruby target version changed to 3.1

## [3.0.0] - 2020-03-10

### Breaking changes
Expand Down
12 changes: 12 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,15 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }

# Specify your gem's dependencies in sec_id.gemspec
gemspec

# Specify your gem's development dependencies below
gem 'rake', '>= 13'

gem 'rspec', '~> 3.9'
gem 'rspec_junit_formatter'

gem 'rubocop', '~> 1.64'
gem 'rubocop-rspec', '~> 3.0'

gem 'simplecov', '~> 0.22', require: false
gem 'simplecov_json_formatter', require: false
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# SecId
[![Gem Version](https://badge.fury.io/rb/sec_id.svg)](https://badge.fury.io/rb/sec_id)
[![Build Status](https://travis-ci.org/svyatov/sec_id.svg?branch=master)](https://travis-ci.org/svyatov/sec_id)
[![Depfu](https://badges.depfu.com/badges/ccb54ed1642be2d4d102b83d7d6a604c/overview.svg)](https://depfu.com/github/svyatov/sec_id?project_id=6878)
![Build Status](https://github.com/github/docs/actions/workflows/main.yml/badge.svg?branch=main)
[![Maintainability](https://api.codeclimate.com/v1/badges/a4759963a5ddc4d55b24/maintainability)](https://codeclimate.com/github/svyatov/sec_id/maintainability)
[![Test Coverage](https://api.codeclimate.com/v1/badges/a4759963a5ddc4d55b24/test_coverage)](https://codeclimate.com/github/svyatov/sec_id/test_coverage)

Expand All @@ -22,7 +21,7 @@ Work in progress:
Add this line to your application's Gemfile:

```ruby
gem 'sec_id', '~> 3.0'
gem 'sec_id', '~> 4.0'
```

And then execute:
Expand Down
28 changes: 15 additions & 13 deletions lib/sec_id/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,22 @@ module SecId
class Base
attr_reader :full_number, :identifier, :check_digit

def self.valid?(id)
new(id).valid?
end
class << self
def valid?(id)
new(id).valid?
end

def self.valid_format?(id)
new(id).valid_format?
end
def valid_format?(id)
new(id).valid_format?
end

def self.restore!(id_without_check_digit)
new(id_without_check_digit).restore!
end
def restore!(id_without_check_digit)
new(id_without_check_digit).restore!
end

def self.check_digit(id)
new(id).calculate_check_digit
def check_digit(id)
new(id).calculate_check_digit
end
end

def initialize(_sec_id_number)
Expand Down Expand Up @@ -89,11 +91,11 @@ def char_to_digit(char)
SecId::CHAR_TO_DIGIT.fetch(char)
end

def mod_10(sum)
def mod10(sum)
(10 - (sum % 10)) % 10
end

def div_10_mod_10(number)
def div10mod10(number)
(number / 10) + (number % 10)
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/sec_id/cusip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class CUSIP < Base
(?<cusip6>[A-Z0-9]{5}[A-Z0-9*@#])
(?<issue>[A-Z0-9*@#]{2}))
(?<check_digit>\d)?
\z/x.freeze
\z/x

attr_reader :cusip6, :issue

Expand All @@ -21,7 +21,7 @@ def initialize(cusip)
end

def calculate_check_digit
return mod_10(modified_luhn_sum) if valid_format?
return mod10(modified_luhn_sum) if valid_format?

raise InvalidFormatError, "CUSIP '#{full_number}' is invalid and check-digit cannot be calculated!"
end
Expand All @@ -34,7 +34,7 @@ def modified_luhn_sum

id_digits.reverse.each_slice(2) do |even, odd|
double_even = (even || 0) * 2
sum += div_10_mod_10(double_even) + div_10_mod_10(odd || 0)
sum += div10mod10(double_even) + div10mod10(odd || 0)
end

sum
Expand Down
4 changes: 2 additions & 2 deletions lib/sec_id/isin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class ISIN < Base
(?<country_code>[A-Z]{2})
(?<nsin>[A-Z0-9]{9}))
(?<check_digit>\d)?
\z/x.freeze
\z/x

attr_reader :country_code, :nsin

Expand All @@ -21,7 +21,7 @@ def initialize(isin)
end

def calculate_check_digit
return mod_10(luhn_sum) if valid_format?
return mod10(luhn_sum) if valid_format?

raise InvalidFormatError, "ISIN '#{full_number}' is invalid and check-digit cannot be calculated!"
end
Expand Down
4 changes: 2 additions & 2 deletions lib/sec_id/sedol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class SEDOL < Base
ID_REGEX = /\A
(?<identifier>[0-9BCDFGHJKLMNPQRSTVWXYZ]{6})
(?<check_digit>\d)?
\z/x.freeze
\z/x

CHARACTER_WEIGHTS = [1, 3, 1, 7, 3, 9].freeze

Expand All @@ -17,7 +17,7 @@ def initialize(sedol)
end

def calculate_check_digit
return mod_10(weighted_sum) if valid_format?
return mod10(weighted_sum) if valid_format?

raise InvalidFormatError, "SEDOL '#{full_number}' is invalid and check-digit cannot be calculated!"
end
Expand Down
2 changes: 1 addition & 1 deletion lib/sec_id/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module SecId
VERSION = '3.0.0'
VERSION = '4.0.0'
end
9 changes: 2 additions & 7 deletions sec_id.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,12 @@ Gem::Specification.new do |spec|
spec.homepage = 'https://github.com/svyatov/sec_id'
spec.license = 'MIT'

spec.required_ruby_version = '>= 2.5.0'
spec.required_ruby_version = '>= 3.1.0'

spec.require_paths = ['lib']
spec.files = `git ls-files -z`.split("\x0").reject do |f|
f.match(%r{^(test|spec|features)/})
end

spec.add_development_dependency 'bundler', '>= 1.16'
spec.add_development_dependency 'rake', '>= 10.0'
spec.add_development_dependency 'rspec', '~> 3.9'
spec.add_development_dependency 'rubocop', '~> 1.18.4'
spec.add_development_dependency 'rubocop-rspec', '~> 1.38'
spec.add_development_dependency 'simplecov', '~> 0.21.2'
spec.metadata['rubygems_mfa_required'] = 'true'
end
26 changes: 13 additions & 13 deletions spec/sec_id/cusip_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

describe '#valid?' do
it 'returns true' do
expect(cusip.valid?).to eq(true)
expect(cusip.valid?).to be(true)
end
end

Expand All @@ -39,7 +39,7 @@

describe '#valid?' do
it 'returns false' do
expect(cusip.valid?).to eq(false)
expect(cusip.valid?).to be(false)
end
end

Expand All @@ -54,9 +54,9 @@
describe '.valid?' do
context 'when CUSIP is incorrect' do
it 'returns false' do
expect(described_class.valid?('5949181')).to eq(false)
expect(described_class.valid?('594918105')).to eq(false) # invalid check-digit
expect(described_class.valid?('5949181045')).to eq(false)
expect(described_class.valid?('5949181')).to be(false)
expect(described_class.valid?('594918105')).to be(false) # invalid check-digit
expect(described_class.valid?('5949181045')).to be(false)
end
end

Expand All @@ -65,7 +65,7 @@
%w[
594918104 38259P508 037833100 17275R102 68389X105 986191302
].each do |cusip_number|
expect(described_class.valid?(cusip_number)).to eq(true)
expect(described_class.valid?(cusip_number)).to be(true)
end
end
end
Expand Down Expand Up @@ -93,18 +93,18 @@
describe '.valid_format?' do
context 'when CUSIP is incorrect' do
it 'returns false' do
expect(described_class.valid_format?('0378331')).to eq(false)
expect(described_class.valid_format?('0378331009')).to eq(false)
expect(described_class.valid_format?('0378331')).to be(false)
expect(described_class.valid_format?('0378331009')).to be(false)
end
end

context 'when CUSIP is valid or missing check-digit' do
it 'returns true' do
expect(described_class.valid_format?('38259P50')).to eq(true)
expect(described_class.valid_format?('38259P508')).to eq(true)
expect(described_class.valid_format?('68389X10')).to eq(true)
expect(described_class.valid_format?('68389X105')).to eq(true)
expect(described_class.valid_format?('986191302')).to eq(true)
expect(described_class.valid_format?('38259P50')).to be(true)
expect(described_class.valid_format?('38259P508')).to be(true)
expect(described_class.valid_format?('68389X10')).to be(true)
expect(described_class.valid_format?('68389X105')).to be(true)
expect(described_class.valid_format?('986191302')).to be(true)
end
end
end
Expand Down
Loading

0 comments on commit 955de77

Please sign in to comment.