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

Compare PubIDs: provide method to ignore year in comparison #12

Open
andrew2net opened this issue Jun 4, 2023 · 4 comments
Open

Compare PubIDs: provide method to ignore year in comparison #12

andrew2net opened this issue Jun 4, 2023 · 4 comments
Assignees
Labels
enhancement New feature or request

Comments

@andrew2net
Copy link

andrew2net commented Jun 4, 2023

We use references without a year to search all years publications of a document. But reference IDs withot year doesn't match to document's PubId with year. We need a way to drop year when compare PubIds.
I suggest to implement an "asymmetric" compare solution. If left operand has year then it's used, otherwise year is ignored.

# false because left operand has year, but right doesn't have or have different year.
pubid_with_year === pubid_without_year
=> false
pubid_with_year1 === pubid_with_year2
=> false

# true because left operand doesn't have year so right operand can have any year or no year at all
pubid_without_year === pubid_with_year
=> true

It blocks relaton/relaton-bsi#24 and relaton/relaton-jis#2

@ronaldtse ronaldtse added the enhancement New feature or request label Jun 5, 2023
@ronaldtse ronaldtse removed this from Metanorma Jun 6, 2023
@github-project-automation github-project-automation bot moved this to 🆕 New in Metanorma Jun 6, 2023
@ronaldtse
Copy link
Contributor

@mico can you please help add this functionality? Thanks.

@ronaldtse ronaldtse changed the title Ignore year when compare PubIds Compare PubIDs: provide method to ignore year in comparison Jun 6, 2023
@ronaldtse
Copy link
Contributor

But === is an object comparator in Ruby?

Why not use something simple like pubid1.without_year == pubid2.without_year?

@andrew2net
Copy link
Author

But === is an object comparator in Ruby?

I'd say if a === b true then b is a member of set a. For example (1..5) === 3 is true, but 3 === (1..5) is false. In our case if left operand doesn't have year then it denotes a set of documents with any year.

Why not use something simple like pubid1.without_year == pubid2.without_year?

Because it depends on a reference. If a reference with year we need to compare with year, otherwise without year. We need something like:

class Pubid
  ...
  def ===(other)
    ...
      && (self.year.nil? || self.year == other.year)
      ...
  end
end

@ronaldtse
Copy link
Contributor

Ahh okay it makes sense. We just need the implementation well documented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants