Skip to content

Commit

Permalink
rename product to selection (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
gkostin1966 committed Jun 11, 2019
1 parent 55f70ab commit 93c4ce1
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 46 deletions.
8 changes: 4 additions & 4 deletions app/modules/lib_ptg_box.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
require_relative 'lib_ptg_box/unmarshaller'

require_relative 'lib_ptg_box/work'
require_relative 'lib_ptg_box/product'
require_relative 'lib_ptg_box/selection'
require_relative 'lib_ptg_box/collection'
require_relative 'lib_ptg_box/lib_ptg_box'

Expand All @@ -19,9 +19,9 @@ module LibPtgBox
# def test
# LibPtgBox.new.collections.each do |collection|
# puts collection.name
# collection.products.each do |product|
# puts "--> " + product.name + " " + product.yyyy + '-' + product.mm + '-' + product.dd
# product.works.each do |work|
# collection.selections.each do |selection|
# puts "--> " + selection.name + " " + selection.yyyy + '-' + selection.mm + '-' + selection.dd
# selection.works.each do |work|
# puts "----> #{work.doi}" unless work.marc?
# end
# end
Expand Down
4 changes: 2 additions & 2 deletions app/modules/lib_ptg_box/catalog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

module LibPtgBox
class Catalog
def initialize(product, complete_marc_file)
@product = product
def initialize(selection, complete_marc_file)
@selection = selection
@complete_marc_file = complete_marc_file
@reader = MARC::XMLReader.new(StringIO.new(complete_marc_file.content))
@marcs = @reader.entries.map { |entry| Unmarshaller::Marc.new(entry) }
Expand Down
4 changes: 2 additions & 2 deletions app/modules/lib_ptg_box/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ def initialize(sub_folder)
@name = sub_folder.name
end

def products
@products ||= @sub_folder.kbart_folder.kbart_files.map { |kbart_file| Product.new(self, kbart_file) }
def selections
@selections ||= @sub_folder.kbart_folder.kbart_files.map { |kbart_file| Selection.new(self, kbart_file) }
end

def catalog
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module LibPtgBox
class Product
class Selection
attr_reader :collection, :name, :year, :yyyy, :mm, :dd

def initialize(collection, kbart_file) # rubocop:disable Metrics/AbcSize
Expand Down
6 changes: 3 additions & 3 deletions app/modules/lib_ptg_box/work.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ module LibPtgBox
class Work
attr_reader :doi

def initialize(product, kbart)
@product = product
def initialize(selection, kbart)
@selection = selection
@kbart = kbart
@doi = kbart.doi
end
Expand All @@ -15,7 +15,7 @@ def marc?
end

def marc
@marc ||= @product.collection.catalog.marc(@doi)
@marc ||= @selection.collection.catalog.marc(@doi)
end
end
end
12 changes: 6 additions & 6 deletions app/runners/assemble_marc_files.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

class AssembleMarcFiles
def run
modified_product = nil
umpebc_collection.products.each do |product|
next unless product.modified_today?
modified_selection = nil
umpebc_collection.selections.each do |selection|
next unless selection.modified_today?

modified_product = product
modified_selection = selection
end
modified_product
modified_selection
end

private
Expand All @@ -23,7 +23,7 @@ def umpebc_collection # rubocop:disable Metrics/MethodLength
umpebc_family = family
break
end
raise 'umpebc product family not found' unless umpebc_family
raise 'umpebc selection family not found' unless umpebc_family

umpebc_family
end
Expand Down
4 changes: 2 additions & 2 deletions spec/modules/lib_ptg_box/catalog_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
require 'rails_helper'

RSpec.describe LibPtgBox::Catalog do
subject(:catalog) { described_class.new(product, complete_marc_file) }
subject(:catalog) { described_class.new(selection, complete_marc_file) }

let(:product) { instance_double(LibPtgBox::Product, 'product') }
let(:selection) { instance_double(LibPtgBox::Selection, 'selection') }
let(:complete_marc_file) { object_double(LibPtgBox::Unmarshaller::MarcFile.new(marc_box_file), 'complete_marc_file') }
let(:marc_box_file) { instance_double(Box::File, 'marc_box_file', content: content) }
let(:content) { instance_double(String, 'content') }
Expand Down
22 changes: 11 additions & 11 deletions spec/modules/lib_ptg_box/collection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,40 +18,40 @@
it { is_expected.to eq(sub_box_folder.name) }
end

describe '#products' do
subject { collection.products }
describe '#selections' do
subject { collection.selections }

let(:kbart_folder) { instance_double(LibPtgBox::Unmarshaller::KbartFolder, 'kbart_folder') }
let(:kbart_file) { object_double(LibPtgBox::Unmarshaller::KbartFile.new(kbart_box_file), 'kbart_box_file') }
let(:kbart_box_file) { instance_double(Box::File, 'kbart_box_file', name: 'Product_0000_0000-00-00.csv') }
let(:product) { 'product' }
let(:kbart_box_file) { instance_double(Box::File, 'kbart_box_file', name: 'Selection_0000_0000-00-00.csv') }
let(:selection) { 'selection' }

before do
allow(sub_folder).to receive(:kbart_folder).and_return(kbart_folder)
allow(kbart_folder).to receive(:kbart_files).and_return([kbart_file])
allow(kbart_file).to receive(:name).and_return(kbart_box_file.name)
allow(LibPtgBox::Product).to receive(:new).with(collection, kbart_file).and_return(product)
allow(LibPtgBox::Selection).to receive(:new).with(collection, kbart_file).and_return(selection)
end

it { is_expected.to contain_exactly(product) }
it { is_expected.to contain_exactly(selection) }
end

describe '#catalog' do
subject { collection.catalog }

let(:marc_folder) { object_double(LibPtgBox::Unmarshaller::MarcFolder.new(marc_box_folder), 'marc_folder') }
let(:marc_box_folder) { instance_double(Box::Folder, 'marc_box_folder', name: 'name') }
let(:product_marc_file) { object_double(LibPtgBox::Unmarshaller::MarcFile.new(product_box_file), 'product_marc_file') }
let(:product_box_file) { instance_double(Box::File, 'product_box_file', name: 'Product_Year.xml') }
let(:selection_marc_file) { object_double(LibPtgBox::Unmarshaller::MarcFile.new(selection_box_file), 'selection_marc_file') }
let(:selection_box_file) { instance_double(Box::File, 'selection_box_file', name: 'Selection_Year.xml') }
let(:complete_marc_file) { object_double(LibPtgBox::Unmarshaller::MarcFile.new(complete_box_file), 'complete_marc_file') }
let(:complete_box_file) { instance_double(Box::File, 'complete_box_file', name: 'Product_Complete.xml', content: content) }
let(:complete_box_file) { instance_double(Box::File, 'complete_box_file', name: 'Selection_Complete.xml', content: content) }
let(:content) { '' }
let(:catalog) { 'catalog' }

before do
allow(sub_folder).to receive(:cataloging_marc_folder).and_return(marc_folder)
allow(marc_folder).to receive(:marc_files).and_return([product_marc_file, complete_marc_file])
allow(product_marc_file).to receive(:name).and_return(product_box_file.name)
allow(marc_folder).to receive(:marc_files).and_return([selection_marc_file, complete_marc_file])
allow(selection_marc_file).to receive(:name).and_return(selection_box_file.name)
allow(complete_marc_file).to receive(:name).and_return(complete_box_file.name)
allow(complete_marc_file).to receive(:content).and_return(complete_box_file.content)
allow(LibPtgBox::Catalog).to receive(:new).with(collection, complete_marc_file).and_return(catalog)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,76 +2,76 @@

require 'rails_helper'

RSpec.describe LibPtgBox::Product do
subject(:product) { described_class.new(collection, kbart_file) }
RSpec.describe LibPtgBox::Selection do
subject(:selection) { described_class.new(collection, kbart_file) }

let(:collection) { instance_double(LibPtgBox::Collection, 'collection') }
let(:kbart_file) { object_double(LibPtgBox::Unmarshaller::KbartFile.new(kbart_box_file), 'kbart_file') }
let(:kbart_box_file) { instance_double(Box::File, 'kbart_box_file', name: kbart_file_name) }
let(:kbart_file_name) { 'Product_0000_0000-00-00.csv' }
let(:kbart_file_name) { 'Selection_0000_0000-00-00.csv' }

before { allow(kbart_file).to receive(:name).and_return(kbart_box_file.name) }

describe '#works' do
subject { product.works }
subject { selection.works }

let(:kbart) { 'kbart' }
let(:work) { 'work' }

before do
allow(kbart_file).to receive(:kbarts).and_return([kbart])
allow(LibPtgBox::Work).to receive(:new).with(product, kbart).and_return(work)
allow(LibPtgBox::Work).to receive(:new).with(selection, kbart).and_return(work)
end

it { is_expected.to contain_exactly(work) }
end

describe '#year?' do
subject { product.year? }
subject { selection.year? }

it { is_expected.to be false }

context 'with year' do
let(:kbart_file_name) { "Product_#{format('%04d', Time.now.year)}_0000-00-00.csv" }
let(:kbart_file_name) { "Selection_#{format('%04d', Time.now.year)}_0000-00-00.csv" }

it { is_expected.to be true }
end
end

describe '#modified_today?' do
subject { product.modified_today? }
subject { selection.modified_today? }

it { is_expected.to be false }

context 'with today' do
let(:today) { Time.now }
let(:kbart_file_name) { "Product_0000_#{format('%04d', today.year)}-#{format('%02d', today.month)}-#{format('%02d', today.day)}.csv" }
let(:kbart_file_name) { "Selection_0000_#{format('%04d', today.year)}-#{format('%02d', today.month)}-#{format('%02d', today.day)}.csv" }

it { is_expected.to be true }
end
end

describe 'modified_this_month?' do
subject { product.modified_this_month? }
subject { selection.modified_this_month? }

it { is_expected.to be false }

context 'with month' do
let(:today) { Time.now }
let(:kbart_file_name) { "Product_0000_#{format('%04d', today.year)}-#{format('%02d', today.month)}-00.csv" }
let(:kbart_file_name) { "Selection_0000_#{format('%04d', today.year)}-#{format('%02d', today.month)}-00.csv" }

it { is_expected.to be true }
end
end

describe 'modified_this_year?' do
subject { product.modified_this_year? }
subject { selection.modified_this_year? }

it { is_expected.to be false }

context 'with year' do
let(:today) { Time.now }
let(:kbart_file_name) { "Product_0000_#{format('%04d', today.year)}-00-00.csv" }
let(:kbart_file_name) { "Selection_0000_#{format('%04d', today.year)}-00-00.csv" }

it { is_expected.to be true }
end
Expand Down
4 changes: 2 additions & 2 deletions spec/modules/lib_ptg_box/work_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
require 'rails_helper'

RSpec.describe LibPtgBox::Work do
subject(:work) { described_class.new(product, kbart) }
subject(:work) { described_class.new(selection, kbart) }

let(:product) { instance_double(LibPtgBox::Product, 'product', collection: collection) }
let(:selection) { instance_double(LibPtgBox::Selection, 'selection', collection: collection) }
let(:collection) { instance_double(LibPtgBox::Collection, 'collection', catalog: catalog) }
let(:catalog) { instance_double(LibPtgBox::Catalog, 'catalog') }
let(:kbart) { instance_double(LibPtgBox::Unmarshaller::Kbart, 'kbart', doi: 'doi') }
Expand Down

0 comments on commit 93c4ce1

Please sign in to comment.