Skip to content

Commit

Permalink
fix: discard date parsing, misc deps updates (#50)
Browse files Browse the repository at this point in the history
* misc dependency updates and version bumps

* sort by modification time instead of filename stuff

* rubocop fix

* get rid of all the date code
  • Loading branch information
gundamu-yunikon authored May 2, 2024
1 parent b290e4a commit 227f91c
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
bump-patch-for-minor-pre-major: true

- if: ${{ steps.release.outputs.release_created }}
uses: actions/checkout@v3
uses: actions/checkout@v4

- if: ${{ steps.release.outputs.release_created }}
name: Set up Ruby
Expand Down
7 changes: 2 additions & 5 deletions .github/workflows/update-database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
name: Update BSB Database & Version
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
Expand All @@ -21,13 +21,10 @@ jobs:
run: bundle exec rake bsb:sync
- id: get-date
run: echo "::set-output name=date::$(date +'%Y-%m-%d')"
- uses: peter-evans/create-pull-request@v4
- uses: peter-evans/create-pull-request@v6
id: raise-pr
with:
branch: "bot/${{ steps.get-date.outputs.date }}"
base: master
title: "fix: ${{ steps.get-date.outputs.date }} periodic update of config/*.json database files."
committer: GitHub Actions <[email protected]>
author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
signoff: false
delete-branch: true
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.1.2
3.3.1
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ gemspec
gem 'bundler', '~> 2.0'
gem 'net-ftp', '~> 0.1.3'
gem 'rake', '~> 13.0'
gem 'rubocop', '~> 1.26'
gem 'rubocop'
2 changes: 1 addition & 1 deletion bsb.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.require_paths = ['lib']

spec.required_ruby_version = '>= 2.7.0'
spec.required_ruby_version = '>= 2.7.7'

spec.add_dependency 'activemodel'

Expand Down
29 changes: 2 additions & 27 deletions lib/auspaynet/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

module Auspaynet
class Client
MONTHS = %w[Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec].freeze

def initialize(host)
@host = host
@ftp = Net::FTP.new(@host)
Expand All @@ -23,35 +21,12 @@ def get(dir, filename)
def list(dir:, matching_filename:, file_format: 'csv')
@ftp.chdir(dir)
files = @ftp.nlst.select do |f|
f.include?(matching_filename) &&
f.include?(file_format) &&
(f.include?("#{current_year}-") || f.include?("#{current_year})"))
f.include?(matching_filename) && f.end_with?(file_format)
end

extract_latest_files(files: files, file_format: file_format)
files.sort_by { |fname| @ftp.mtime(fname) }
ensure
@ftp.chdir('/')
end

private

def current_year
Time.now.strftime('%y')
end

def extract_latest_files(files:, file_format:)
files.sort_by do |filename|
file_for_month(filename: filename, file_format: file_format)
end
end

def file_for_month(filename:, file_format:)
month_from_filename = filename.gsub(/(#{filename}|#{file_format}|\W|\d)/, '')
month_number(month_from_filename)
end

def month_number(month_from_filename)
MONTHS.find_index(month_from_filename)
end
end
end

0 comments on commit 227f91c

Please sign in to comment.