metanorma / pubid-core

BSD 2-Clause "Simplified" License
1 stars 0 forks source link

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

Open andrew2net opened 1 year ago

andrew2net commented 1 year ago

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 https://github.com/relaton/relaton-bsi/issues/24 and https://github.com/relaton/relaton-jis/issues/2

ronaldtse commented 1 year ago

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

ronaldtse commented 1 year ago

But === is an object comparator in Ruby?

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

andrew2net commented 1 year ago

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 commented 1 year ago

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