Class: Eco::API::UseCases::GraphQL::Helpers::Location::TagsRemap::TagsMap
- Defined in:
- lib/eco/api/usecases/graphql/helpers/location/tags_remap/tags_map.rb
Instance Attribute Summary collapse
-
#from ⇒ Object
readonly
Returns the value of attribute from.
-
#to ⇒ Object
readonly
Returns the value of attribute to.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #any?(&block) ⇒ Boolean
- #both?(&block) ⇒ Boolean
- #goes_after?(other) ⇒ Boolean
- #goes_before?(other) ⇒ Boolean
-
#initialize(from, to) ⇒ TagsMap
constructor
A new instance of TagsMap.
- #maps? ⇒ Boolean
- #move? ⇒ Boolean
- #rename? ⇒ Boolean
- #to_csv_row ⇒ Object
Constructor Details
Instance Attribute Details
#from ⇒ Object (readonly)
Returns the value of attribute from.
4 5 6 |
# File 'lib/eco/api/usecases/graphql/helpers/location/tags_remap/tags_map.rb', line 4 def from @from end |
#to ⇒ Object (readonly)
Returns the value of attribute to.
4 5 6 |
# File 'lib/eco/api/usecases/graphql/helpers/location/tags_remap/tags_map.rb', line 4 def to @to end |
Instance Method Details
#<=>(other) ⇒ Object
Note:
to create a stable sort we assume self
is a sorted element
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/eco/api/usecases/graphql/helpers/location/tags_remap/tags_map.rb', line 16 def <=>(other) # rubocop:disable Metrics/AbcSize return -1 if maps? && !other.maps? return 1 if !maps? && other.maps? return -1 if rename? && other.move? return 1 if move? && other.rename? return -1 if rename? && other.rename? # both are being moved (specific/long mappings first) return 1 if from.subset_of?(other.from) return -1 if from.superset_of?(other.from) return -1 if (from & other.from).empty? return -1 if from.length >= other.from.length return 1 if from.length < other.from.length -1 end |
#any?(&block) ⇒ Boolean
45 46 47 |
# File 'lib/eco/api/usecases/graphql/helpers/location/tags_remap/tags_map.rb', line 45 def any?(&block) [from, to].any?(&block) end |
#both?(&block) ⇒ Boolean
41 42 43 |
# File 'lib/eco/api/usecases/graphql/helpers/location/tags_remap/tags_map.rb', line 41 def both?(&block) [from, to].all?(&block) end |
#goes_after?(other) ⇒ Boolean
Note:
to create a stable sort we assume self
is a sorted element
37 38 39 |
# File 'lib/eco/api/usecases/graphql/helpers/location/tags_remap/tags_map.rb', line 37 def goes_after?(other) (self <=> other) == 1 end |
#goes_before?(other) ⇒ Boolean
Note:
to create a stable sort we assume self
is a sorted element
32 33 34 |
# File 'lib/eco/api/usecases/graphql/helpers/location/tags_remap/tags_map.rb', line 32 def goes_before?(other) (self <=> other) == -1 end |
#maps? ⇒ Boolean
49 50 51 52 53 |
# File 'lib/eco/api/usecases/graphql/helpers/location/tags_remap/tags_map.rb', line 49 def maps? return false if any?(&:empty?) return false if from == to true end |
#move? ⇒ Boolean
60 61 62 63 |
# File 'lib/eco/api/usecases/graphql/helpers/location/tags_remap/tags_map.rb', line 60 def move? return false unless maps? !rename? end |
#rename? ⇒ Boolean
55 56 57 58 |
# File 'lib/eco/api/usecases/graphql/helpers/location/tags_remap/tags_map.rb', line 55 def rename? return false unless maps? both? {|set| set.length == 1} end |
#to_csv_row ⇒ Object
11 12 13 |
# File 'lib/eco/api/usecases/graphql/helpers/location/tags_remap/tags_map.rb', line 11 def to_csv_row [from.to_s, to.to_s] end |