Module: X::Resources::ValueEquality
- Included in:
- MatchingRule, PersonalizedTrend, PostUsage, Trend
- Defined in:
- x-resources/lib/x/resources/value_equality.rb
Overview
Equality of what an API response held that has no identifier, by its class and attributes
A trend or the usage of a project has no identifier to tell it by, and a rule a post matched is told by its tag as well as its identifier, so two are equal when they are of the same class and hold the same attributes, and equal ones share a hash, so that uniq and a Hash key tell them apart. Every attribute counts, so a topic that trends in two places, with a count of posts in each, is two trends that differ; compare their names to find the topics two places share, as trends.map(&:name).intersect?(other_trends.map(&:name)).
Internal to x-resources: the methods it gives X::Trend, X::PersonalizedTrend, X::PostUsage, and X::MatchingRule are public API, but the module is only how they are shared, and which classes include it can change within 1.x.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
Check whether another object holds the same attributes.
-
#hash ⇒ Integer
The hash of the object, which equal objects share.
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
Check whether another object holds the same attributes
25 |
# File 'x-resources/lib/x/resources/value_equality.rb', line 25 def ==(other) = other.instance_of?(self.class) && attrs.eql?((_ = other).attrs) |
#hash ⇒ Integer
The hash of the object, which equal objects share
34 |
# File 'x-resources/lib/x/resources/value_equality.rb', line 34 def hash = [self.class, attrs].hash |