Class: ArcWeld::Cli::RelationReaders::CsvCategoryUri

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/arc_weld/cli/readers/relation_csv_category_uri.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#constantize, #uri_join

Constructor Details

#initialize(*args) ⇒ CsvCategoryUri

Returns a new instance of CsvCategoryUri.



11
12
13
14
15
16
17
18
19
20
# File 'lib/arc_weld/cli/readers/relation_csv_category_uri.rb', line 11

def initialize(*args)
  Hash[*args].each {|k,v| self.send(format('%s=',k),v)}
  @csv = CSV.open(path)
  @keys = csv.readline
  @src_type, @src_select, *unused= keys.flat_map do |k|
     k.split(':')
  end
  @src_class=ArcWeld.const_get(constantize(src_type))
  self
end

Instance Attribute Details

#csvObject (readonly)

Returns the value of attribute csv.



9
10
11
# File 'lib/arc_weld/cli/readers/relation_csv_category_uri.rb', line 9

def csv
  @csv
end

#inputsObject

Returns the value of attribute inputs.



8
9
10
# File 'lib/arc_weld/cli/readers/relation_csv_category_uri.rb', line 8

def inputs
  @inputs
end

#keysObject (readonly)

Returns the value of attribute keys.



9
10
11
# File 'lib/arc_weld/cli/readers/relation_csv_category_uri.rb', line 9

def keys
  @keys
end

#pathObject

Returns the value of attribute path.



6
7
8
# File 'lib/arc_weld/cli/readers/relation_csv_category_uri.rb', line 6

def path
  @path
end

#relationship_typeObject

Returns the value of attribute relationship_type.



6
7
8
# File 'lib/arc_weld/cli/readers/relation_csv_category_uri.rb', line 6

def relationship_type
  @relationship_type
end

#src_classObject

Returns the value of attribute src_class.



6
7
8
# File 'lib/arc_weld/cli/readers/relation_csv_category_uri.rb', line 6

def src_class
  @src_class
end

#src_selectObject

Returns the value of attribute src_select.



6
7
8
# File 'lib/arc_weld/cli/readers/relation_csv_category_uri.rb', line 6

def src_select
  @src_select
end

#src_typeObject (readonly)

Returns the value of attribute src_type.



9
10
11
# File 'lib/arc_weld/cli/readers/relation_csv_category_uri.rb', line 9

def src_type
  @src_type
end

Instance Method Details

#destinations(inputs) ⇒ Object



26
27
28
# File 'lib/arc_weld/cli/readers/relation_csv_category_uri.rb', line 26

def destinations(inputs)
  []
end

#relate(inputs) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/arc_weld/cli/readers/relation_csv_category_uri.rb', line 30

def relate(inputs)
  csv.each do |selected_src, category_uri|
    src_instance=sources(inputs).find {|s| s.send(src_select)==selected_src}
    
    if (src_instance.nil?)
      STDERR.puts format('could not %s %s/%s',
                         relationship_type,
                         selected_src)
    else
       src_instance.send(relationship_type,category_uri)
    end
  end
end

#sources(inputs) ⇒ Object



22
23
24
# File 'lib/arc_weld/cli/readers/relation_csv_category_uri.rb', line 22

def sources(inputs)
  inputs[src_type]
end