Class: Eco::API::UseCases::GraphQL::Helpers::Location::TagsRemap
- Inherits:
-
Object
- Object
- Eco::API::UseCases::GraphQL::Helpers::Location::TagsRemap
show all
- Includes:
- Enumerable
- Defined in:
- lib/eco/api/usecases/graphql/helpers/location/tags_remap.rb,
lib/eco/api/usecases/graphql/helpers/location/tags_remap/tags_map.rb,
lib/eco/api/usecases/graphql/helpers/location/tags_remap/tags_set.rb
Defined Under Namespace
Classes: TagsMap, TagsSet
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Instance Attribute Details
Returns the value of attribute from.
10
11
12
|
# File 'lib/eco/api/usecases/graphql/helpers/location/tags_remap.rb', line 10
def from
@from
end
|
Returns the value of attribute to.
10
11
12
|
# File 'lib/eco/api/usecases/graphql/helpers/location/tags_remap.rb', line 10
def to
@to
end
|
Class Method Details
.correct_pair?(pair) ⇒ Boolean
3
4
5
6
|
# File 'lib/eco/api/usecases/graphql/helpers/location/tags_remap.rb', line 3
def self.correct_pair?(pair)
correct_pair = pair.is_a?(Array)
correct_pair && pair.length == 2
end
|
Instance Method Details
65
66
67
68
|
# File 'lib/eco/api/usecases/graphql/helpers/location/tags_remap.rb', line 65
def <<(pair)
raise ArgumentError, "Expecting pair of Array in Array. Given: #{pair}" unless self.class.correct_pair?(pair)
add(*pair)
end
|
#add(from, to) ⇒ Object
70
71
72
73
74
|
# File 'lib/eco/api/usecases/graphql/helpers/location/tags_remap.rb', line 70
def add(from, to)
raise ArgumentError, "Expecting Array. Given: #{from.class}" unless from.is_a?(Array)
raise ArgumentError, "Expecting Array. Given: #{to.class}" unless to.is_a?(Array)
new_src TagsMap.new(from, to)
end
|
#each(&block) ⇒ Object
16
17
18
19
|
# File 'lib/eco/api/usecases/graphql/helpers/location/tags_remap.rb', line 16
def each(&block)
return to_enum(:each) unless block
src_maps.each(&block)
end
|
#empty? ⇒ Boolean
Note:
it assumes that:
- renames go before moving nodes
- moving nodes does not include a rename
- moving nodes includes all the path on both, source and destination tags
Note:
DISABLED: the order should be that in what the operations happened!
An important thing is that all the path is always included in the mappings.
- The only way that this would work is to apply upper (previous) tags_maps
to subsequent ones. But the order should still be kept!
Sorts the maps in the correct order
def sorted_maps
[].tap do |sorted|
src_maps.each do |curr_map|
pos = nil
sorted.each_with_index.reverse_each do |prev_map, idx|
pos = idx + 1 if prev_map.goes_before?(curr_map)
break if pos
end
sorted.insert(pos || 0, curr_map)
end
end
end
61
62
63
|
# File 'lib/eco/api/usecases/graphql/helpers/location/tags_remap.rb', line 61
def empty?
src_maps.empty?
end
|
12
13
14
|
# File 'lib/eco/api/usecases/graphql/helpers/location/tags_remap.rb', line 12
def src_maps
@src_maps ||= []
end
|
#to_csv(filename) ⇒ Object
21
22
23
24
25
26
27
28
|
# File 'lib/eco/api/usecases/graphql/helpers/location/tags_remap.rb', line 21
def to_csv(filename)
CSV.open(filename, "w") do |fd|
fd << %w[src_tags dst_tags]
each do |tags_map|
fd << tags_map.to_csv_row
end
end
end
|
30
31
32
33
34
35
36
37
|
# File 'lib/eco/api/usecases/graphql/helpers/location/tags_remap.rb', line 30
def to_s
"".tap do |str|
each.map do |tags_map|
from, to = tags_map.to_csv_row
str << " • '#{from}' => '#{to}'\n"
end
end
end
|