Module: Stupidedi::Editor::FortyTenEd::N4

Defined in:
lib/stupidedi/editor/004010/N4.rb

Instance Method Summary collapse

Instance Method Details

#critique_n4(n4, acc)



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/stupidedi/editor/004010/N4.rb', line 8

def critique_n4(n4, acc)
  edit(:N4) do
    usa_canada =
      n4.element(2).select(&:present?).defined? ||
      n4.element(4).select(&:blank?).defined?   ||
      n4.element(4).select{|e| e.node == "US" }.defined? ||
      n4.element(7).select(&:blank?).defined?

    # State or Province Code
    n4.element(2).tap do |e|
      if usa_canada
        if e.node.blank? and e.node.situational?
          # Required
        end
      else
        if e.node.present? and e.node.situational?
          # Forbidden
        end
      end
    end

    # Postal Code
    n4.element(3).tap do |e|
      if usa_canada and e.node =~ /^(\d{1,8}|\d{10,})$/
        acc.warn(e, "must be 9-digits for usa")
      end
    end

    # Country Code
    n4.element(4).tap do |e|
      if usa_canada
        if e.node.present? and e.node.situational?
          # Forbidden
        end
      else
        # Country codes 2-digit from ISO 3166
      end
    end

    # Country Subdivision Code
  # n4.element(7).tap do |e|
  #   if usa_canada
  #     if e.node.present? and e.node.situational?
  #       # Forbidden
  #     end
  #   else
  #     # Country subdivision codes from ISO 3166
  #   end
  # end
  end
end