Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Entity class for basic entity methods implementation #32

Merged
merged 1 commit into from
Nov 18, 2023
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
1 change: 1 addition & 0 deletions lib/pubid/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
require_relative "core/harmonized_stage_code"
require_relative "core/stage"
require_relative "core/typed_stage"
require_relative "core/entity"
11 changes: 11 additions & 0 deletions lib/pubid/core/entity.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Pubid::Core
class Entity
def ==(other)
instance_variables.map do |var|
return false unless instance_variable_get(var) == other.instance_variable_get(var)
end

true
end
end
end
36 changes: 36 additions & 0 deletions spec/pubid_core/entity_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
module Pubid::Core
class TestEntity < Entity
attr_accessor :type, :number

def initialize(type:,number:)
@number, @type = number, type
end
end

RSpec.describe TestEntity do
describe "#==" do
subject do
first_entity == second_entity
end

let(:first_entity) do
described_class.new(number: 1, type: 2)
end
let(:second_entity) do
described_class.new(number: 1, type: 2)
end

context "when have equal entity parameters" do
it { is_expected.to be_truthy }
end

context "when different parameters" do
let(:second_entity) do
described_class.new(number: 1, type: 3)
end

it { is_expected.to be_falsey }
end
end
end
end