Class: Eco::API::UseCases::GraphQL::Helpers::Location::TagsRemap::TagsSet

Inherits:
Object
  • Object
show all
Defined in:
lib/eco/api/usecases/graphql/helpers/location/tags_remap/tags_set.rb

Constant Summary collapse

COMPARE_METHODS =
%i[< <= == > >=].freeze
OPERATE_METHODS =
%i[& + - ^].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tags) ⇒ TagsSet

Returns a new instance of TagsSet.



32
33
34
35
# File 'lib/eco/api/usecases/graphql/helpers/location/tags_remap/tags_set.rb', line 32

def initialize(tags)
  @ini_tags = value_to_a(tags)
  @set      = to_set(tags)
end

Instance Attribute Details

#setObject (readonly)

Returns the value of attribute set.



30
31
32
# File 'lib/eco/api/usecases/graphql/helpers/location/tags_remap/tags_set.rb', line 30

def set
  @set
end

Class Method Details

.attr_compare(*attrs) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/eco/api/usecases/graphql/helpers/location/tags_remap/tags_set.rb', line 5

def attr_compare(*attrs)
  attrs.each do |attr|
    meth = "#{attr}".to_sym # rubocop:disable Style/RedundantInterpolation
    define_method meth do |value|
      set.send(meth, to_set(value))
    end
  end
end

.attr_operate(*attrs) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/eco/api/usecases/graphql/helpers/location/tags_remap/tags_set.rb', line 14

def attr_operate(*attrs)
  attrs.each do |attr|
    meth = "#{attr}".to_sym # rubocop:disable Style/RedundantInterpolation
    define_method meth do |value|
      self.class.new(set.send(meth, to_set(value)))
    end
  end
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/eco/api/usecases/graphql/helpers/location/tags_remap/tags_set.rb', line 53

def empty?
  set.empty?
end

#include?(value) ⇒ Boolean

Returns:

  • (Boolean)


57
58
59
60
61
# File 'lib/eco/api/usecases/graphql/helpers/location/tags_remap/tags_set.rb', line 57

def include?(value)
  value = value.to_s.strip
  return false if value.empty?
  set.include?(value)
end

#include_any?(value) ⇒ Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/eco/api/usecases/graphql/helpers/location/tags_remap/tags_set.rb', line 63

def include_any?(value)
  value.to_a.any? {|tag| include?(tag)}
end

#lengthObject



37
38
39
# File 'lib/eco/api/usecases/graphql/helpers/location/tags_remap/tags_set.rb', line 37

def length
  set.length
end

#subset_of?(value) ⇒ Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/eco/api/usecases/graphql/helpers/location/tags_remap/tags_set.rb', line 67

def subset_of?(value)
  set.subset?(to_set(value))
end

#superset_of?(value) ⇒ Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/eco/api/usecases/graphql/helpers/location/tags_remap/tags_set.rb', line 71

def superset_of?(value)
  set.superset?(to_set(value))
end

#tagsObject



41
42
43
# File 'lib/eco/api/usecases/graphql/helpers/location/tags_remap/tags_set.rb', line 41

def tags
  ini_tags.compact.map(&:upcase)
end

#to_aObject



45
46
47
# File 'lib/eco/api/usecases/graphql/helpers/location/tags_remap/tags_set.rb', line 45

def to_a
  tags
end

#to_sObject



49
50
51
# File 'lib/eco/api/usecases/graphql/helpers/location/tags_remap/tags_set.rb', line 49

def to_s
  tags.join('|')
end