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

Inherits:
Object
  • Object
show all
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

#fromObject (readonly)

Returns the value of attribute from.



9
10
11
# File 'lib/eco/api/usecases/graphql/helpers/location/tags_remap.rb', line 9

def from
  @from
end

#toObject (readonly)

Returns the value of attribute to.



9
10
11
# File 'lib/eco/api/usecases/graphql/helpers/location/tags_remap.rb', line 9

def to
  @to
end

Class Method Details

.correct_pair?(pair) ⇒ Boolean

Returns:

  • (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

#<<(pair) ⇒ Object

Raises:

  • (ArgumentError)


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

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

Raises:

  • (ArgumentError)


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

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



11
12
13
14
# File 'lib/eco/api/usecases/graphql/helpers/location/tags_remap.rb', line 11

def each(&block)
  return to_enum(:each) unless block
  src_maps.each(&block)
end

#empty?Boolean

Note:

it assumes that:

  1. renames go before moving nodes
  2. moving nodes does not include a rename
  3. 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

Returns:

  • (Boolean)


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

def empty?
  src_maps.empty?
end

#to_csv(filename) ⇒ Object



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

def to_csv(filename)
  CSV.open(filename, "w") do |fd|
    fd << ["src_tags", "dst_tags"]
    each do |tags_map|
      fd << tags_map.to_csv_row
    end
  end
end

#to_sObject



25
26
27
28
29
30
31
32
33
# File 'lib/eco/api/usecases/graphql/helpers/location/tags_remap.rb', line 25

def to_s
  "".tap do |str|
    each.map do |tags_map|
      from, to = tags_map.to_csv_row
      str << " • from: #{from}\n"
      str << "   • to: #{to}\n"
    end
  end
end