Class: BerkeleyLibrary::TIND::Mapping::SingleRule

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/berkeley_library/tind/mapping/single_rule.rb

Overview

TODO: ADD CSV VALIDATION, WHEN NEED ADD A NEW MAPPING CSV FILE

  1. not empty row
  2. a subfield name can appear in either normal mapping or combine mapping, not both
  3. single map has the same amount of from names and to names
  4. Combine mappping should have tree columns, validate more?
  5. Combine from_subfield, to_subfield should have values, no empty
  6. Tag from row[:map_if_no_this_tag_subfield_existed]), row[:map_if_no_this_tag_existed] # This tag should be the same as destination tag
  7. In single map csv, one row cannot have both "map_if_no_this_tag_existed" (245) and ":map_if_no_this_tag_subfield_existed" (245__b) because tag in these two column are identical
  8. csv file validation - a row should have coulumns: tag origin and destintation ? single rule
  9. Validating these column names
  10. csv file validation - a row should have coulumns: tag origin and destintation ? single rule
  11. validating headers
  12. Formats for some of the columns

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util

alma_datafield, collection_config_correct?, concatenation_symbol, csv_rows, datafield, from_xml, indicator, order_subfields, qualified_alma_record?, remove_extra_symbol, subfield, subfield_hash, symbols, tag_symbol

Methods included from AlmaBase

#base_save, #base_tind_record

Constructor Details

#initialize(row) ⇒ SingleRule

Returns a new instance of SingleRule.



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/berkeley_library/tind/mapping/single_rule.rb', line 31

def initialize(row)
  @tag_origin = row[:tag_origin]
  @tag_destination = row[:tag_destination]
  @indicator = Util.indicator(row[:new_indecator])
  @pre_existed_tag = row[:map_if_no_this_tag_existed]
  @pre_existed_tag_subfield = existed_tag_subfield(row[:map_if_no_this_tag_subfield_existed]) # This tag should be the same as destination tag
  @single_rule_hash = single_map_dic(row[:subfield_single_from], row[:subfield_single_to])
  @single_rule_subfield_excluded_hash = single_map_subfield_excluded_dic
  @combined_rules = rules_with_same_subfield_name(row)
  @subfields_order = order(row[:order])
end

Instance Attribute Details

#combined_rulesObject (readonly)

Returns the value of attribute combined_rules.



28
29
30
# File 'lib/berkeley_library/tind/mapping/single_rule.rb', line 28

def combined_rules
  @combined_rules
end

#indicatorObject (readonly)

Returns the value of attribute indicator.



23
24
25
# File 'lib/berkeley_library/tind/mapping/single_rule.rb', line 23

def indicator
  @indicator
end

#pre_existed_tagObject (readonly)

Returns the value of attribute pre_existed_tag.



24
25
26
# File 'lib/berkeley_library/tind/mapping/single_rule.rb', line 24

def pre_existed_tag
  @pre_existed_tag
end

#pre_existed_tag_subfieldObject (readonly)

Returns the value of attribute pre_existed_tag_subfield.



25
26
27
# File 'lib/berkeley_library/tind/mapping/single_rule.rb', line 25

def pre_existed_tag_subfield
  @pre_existed_tag_subfield
end

#single_rule_hashObject (readonly)

Returns the value of attribute single_rule_hash.



26
27
28
# File 'lib/berkeley_library/tind/mapping/single_rule.rb', line 26

def single_rule_hash
  @single_rule_hash
end

#single_rule_subfield_excluded_hashObject (readonly)

Returns the value of attribute single_rule_subfield_excluded_hash.



27
28
29
# File 'lib/berkeley_library/tind/mapping/single_rule.rb', line 27

def single_rule_subfield_excluded_hash
  @single_rule_subfield_excluded_hash
end

#subfields_orderObject (readonly)

Returns the value of attribute subfields_order.



29
30
31
# File 'lib/berkeley_library/tind/mapping/single_rule.rb', line 29

def subfields_order
  @subfields_order
end

#tag_destinationObject (readonly)

Returns the value of attribute tag_destination.



22
23
24
# File 'lib/berkeley_library/tind/mapping/single_rule.rb', line 22

def tag_destination
  @tag_destination
end

#tag_originObject (readonly)

Returns the value of attribute tag_origin.



21
22
23
# File 'lib/berkeley_library/tind/mapping/single_rule.rb', line 21

def tag_origin
  @tag_origin
end

Instance Method Details

#rules_with_same_subfield_name(row) ⇒ Object

  1. Return an array of combined rules, an item in the array is an array of rules which have the same 'to subfield name'
  2. An example: [[["a,b,c,d", "b", "--"],["o,p,q", "b", ""]],[["x,y,z", "a", "--"]]]


46
47
48
49
50
51
52
# File 'lib/berkeley_library/tind/mapping/single_rule.rb', line 46

def rules_with_same_subfield_name(row)
  rules = all_combined_rules(row)
  identical_to_subfield_names = unique_tosubfield_names(rules)
  identical_to_subfield_names.each_with_object([]) do |name, result|
    result << rules_with_sametosubfield(name, rules)
  end
end