Skip to content

Commit

Permalink
rename product_family to collection (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
gkostin1966 committed Jun 11, 2019
1 parent 1fc6f1e commit 55f70ab
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 33 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 @@ -5,7 +5,7 @@

require_relative 'lib_ptg_box/work'
require_relative 'lib_ptg_box/product'
require_relative 'lib_ptg_box/product_family'
require_relative 'lib_ptg_box/collection'
require_relative 'lib_ptg_box/lib_ptg_box'

module LibPtgBox
Expand All @@ -17,9 +17,9 @@ module LibPtgBox
#
# class << self
# def test
# LibPtgBox.new.product_families.each do |product_family|
# puts product_family.name
# product_family.products.each do |product|
# 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|
# puts "----> #{work.doi}" unless work.marc?
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module LibPtgBox
class ProductFamily
class Collection
attr_reader :name

def initialize(sub_folder)
Expand Down
4 changes: 2 additions & 2 deletions app/modules/lib_ptg_box/lib_ptg_box.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

module LibPtgBox
class LibPtgBox
def product_families
@product_families ||= Unmarshaller::RootFolder.sub_folders.map { |sub_folder| ProductFamily.new(sub_folder) }
def collections
@collections ||= Unmarshaller::RootFolder.sub_folders.map { |sub_folder| Collection.new(sub_folder) }
end
end
end
6 changes: 3 additions & 3 deletions app/modules/lib_ptg_box/product.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

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

def initialize(product_family, kbart_file) # rubocop:disable Metrics/AbcSize
@product_family = product_family
def initialize(collection, kbart_file) # rubocop:disable Metrics/AbcSize
@collection = collection
@kbart_file = kbart_file
match = /(^.+)_(\d{4})(.*)?_(\d{4})-(\d{2})-(\d{2})\.(.+$)/.match(@kbart_file.name)
@name = match[1] + '_' + match[2] + match[3]
Expand Down
2 changes: 1 addition & 1 deletion app/modules/lib_ptg_box/work.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def marc?
end

def marc
@marc ||= @product.product_family.catalog.marc(@doi)
@marc ||= @product.collection.catalog.marc(@doi)
end
end
end
10 changes: 5 additions & 5 deletions app/runners/assemble_marc_files.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class AssembleMarcFiles
def run
modified_product = nil
umpebc_product_family.products.each do |product|
umpebc_collection.products.each do |product|
next unless product.modified_today?

modified_product = product
Expand All @@ -13,11 +13,11 @@ def run

private

def umpebc_product_family # rubocop:disable Metrics/MethodLength
@umpebc_product_family ||= begin
product_families = LibPtgBox::LibPtgBox.new.product_families
def umpebc_collection # rubocop:disable Metrics/MethodLength
@umpebc_collection ||= begin
collections = LibPtgBox::LibPtgBox.new.collections
umpebc_family = nil
product_families.each do |family|
collections.each do |family|
next unless /umpebc/i.match?(family.name)

umpebc_family = family
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@

require 'rails_helper'

RSpec.describe LibPtgBox::ProductFamily do
subject(:product_family) { described_class.new(sub_folder) }
RSpec.describe LibPtgBox::Collection do
subject(:collection) { described_class.new(sub_folder) }

let(:sub_folder) { object_double(LibPtgBox::Unmarshaller::SubFolder.new(sub_box_folder), 'sub_folder') }
let(:sub_box_folder) { instance_double(Box::Folder, 'sub_box_folder', name: 'Product_Family') }
let(:sub_box_folder) { instance_double(Box::Folder, 'sub_box_folder', name: 'Collection') }

before do
allow(sub_folder).to receive(:name).and_return(sub_box_folder.name)
end

describe '#name' do
subject { product_family.name }
subject { collection.name }

it { is_expected.to eq(sub_box_folder.name) }
end

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

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') }
Expand All @@ -30,14 +30,14 @@
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(product_family, kbart_file).and_return(product)
allow(LibPtgBox::Product).to receive(:new).with(collection, kbart_file).and_return(product)
end

it { is_expected.to contain_exactly(product) }
end

describe '#catalog' do
subject { product_family.catalog }
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') }
Expand All @@ -54,7 +54,7 @@
allow(product_marc_file).to receive(:name).and_return(product_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(product_family, complete_marc_file).and_return(catalog)
allow(LibPtgBox::Catalog).to receive(:new).with(collection, complete_marc_file).and_return(catalog)
end

it { is_expected.to eq(catalog) }
Expand Down
10 changes: 5 additions & 5 deletions spec/modules/lib_ptg_box/lib_ptg_box_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
require 'rails_helper'

RSpec.describe LibPtgBox::LibPtgBox do
describe "#product_families" do
subject { described_class.new.product_families }
describe "#collections" do
subject { described_class.new.collections }

let(:sub_folder) { 'sub_folder' }
let(:product_family) { 'product_family' }
let(:collection) { 'collection' }

before do
allow(LibPtgBox::Unmarshaller::RootFolder).to receive(:sub_folders).and_return([sub_folder])
allow(LibPtgBox::ProductFamily).to receive(:new).with(sub_folder).and_return(product_family)
allow(LibPtgBox::Collection).to receive(:new).with(sub_folder).and_return(collection)
end

it { is_expected.to contain_exactly(product_family) }
it { is_expected.to contain_exactly(collection) }
end
end
4 changes: 2 additions & 2 deletions spec/modules/lib_ptg_box/product_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
require 'rails_helper'

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

let(:product_family) { instance_double(LibPtgBox::ProductFamily, 'product_family') }
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' }
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 @@ -5,8 +5,8 @@
RSpec.describe LibPtgBox::Work do
subject(:work) { described_class.new(product, kbart) }

let(:product) { instance_double(LibPtgBox::Product, 'product', product_family: product_family) }
let(:product_family) { instance_double(LibPtgBox::ProductFamily, 'product_family', catalog: catalog) }
let(:product) { instance_double(LibPtgBox::Product, 'product', 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') }
let(:marc) { nil }
Expand Down

0 comments on commit 55f70ab

Please sign in to comment.