Class: JapanShippingCSV::Ehiden::FieldSpec

Inherits:
Struct
  • Object
show all
Defined in:
lib/japan_shipping_csv/ehiden.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#default_valueObject

Returns the value of attribute default_value



5
6
7
# File 'lib/japan_shipping_csv/ehiden.rb', line 5

def default_value
  @default_value
end

#descriptionObject

Returns the value of attribute description



5
6
7
# File 'lib/japan_shipping_csv/ehiden.rb', line 5

def description
  @description
end

#headerObject

Returns the value of attribute header



5
6
7
# File 'lib/japan_shipping_csv/ehiden.rb', line 5

def header
  @header
end

#is_requiredObject

Returns the value of attribute is_required



5
6
7
# File 'lib/japan_shipping_csv/ehiden.rb', line 5

def is_required
  @is_required
end

#max_lengthObject

Returns the value of attribute max_length



5
6
7
# File 'lib/japan_shipping_csv/ehiden.rb', line 5

def max_length
  @max_length
end

#valid_encodingsObject

Returns the value of attribute valid_encodings



5
6
7
# File 'lib/japan_shipping_csv/ehiden.rb', line 5

def valid_encodings
  @valid_encodings
end

#valid_valuesObject

Returns the value of attribute valid_values



5
6
7
# File 'lib/japan_shipping_csv/ehiden.rb', line 5

def valid_values
  @valid_values
end

Instance Method Details

#encoding_errors(value) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/japan_shipping_csv/ehiden.rb', line 6

def encoding_errors(value)
  if !is_required && (value.nil? || value.empty?)
    return []
  end
  if is_required && (value.nil? || value.empty?)
    return ["value is required"]
  end

  results = []

  if !valid_values.nil? && !valid_values.include?(value)
    results << "must be one of #{valid_values.join(", ")}"
  end
  if value.length > max_length
    results << "is longer than #{max_length} characters"
  end
  if valid_encodings
    # TODO
    # go through each character in the value, and veriy that it matches the valid encodings
    if !Encoding::is_valid_string(value, valid_encodings)
      results << "contains invalid character"
    end
  end
  results
end