Class: Eancom::Edifact::Data
- Inherits:
-
Object
- Object
- Eancom::Edifact::Data
- Defined in:
- lib/eancom/edifact/data.rb
Defined Under Namespace
Classes: LengthError, NotFoundInDictionary, RequiredError, TypeError
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#dictionary ⇒ Object
Returns the value of attribute dictionary.
-
#length ⇒ Object
Returns the value of attribute length.
-
#required ⇒ Object
Returns the value of attribute required.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #identifier(value) ⇒ Object
-
#initialize(type:, length:, dictionary: nil, description:, required:) ⇒ Data
constructor
A new instance of Data.
- #to_s ⇒ Object
- #valid?(key, value) ⇒ Boolean
Constructor Details
#initialize(type:, length:, dictionary: nil, description:, required:) ⇒ Data
Returns a new instance of Data.
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/eancom/edifact/data.rb', line 11 def initialize(type:, length:, dictionary: nil, description:, required: ) @type = type @length = length @dictionary = dictionary @description = description @required = required end |
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
9 10 11 |
# File 'lib/eancom/edifact/data.rb', line 9 def description @description end |
#dictionary ⇒ Object
Returns the value of attribute dictionary.
9 10 11 |
# File 'lib/eancom/edifact/data.rb', line 9 def dictionary @dictionary end |
#length ⇒ Object
Returns the value of attribute length.
9 10 11 |
# File 'lib/eancom/edifact/data.rb', line 9 def length @length end |
#required ⇒ Object
Returns the value of attribute required.
9 10 11 |
# File 'lib/eancom/edifact/data.rb', line 9 def required @required end |
#type ⇒ Object
Returns the value of attribute type.
9 10 11 |
# File 'lib/eancom/edifact/data.rb', line 9 def type @type end |
Instance Method Details
#identifier(value) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/eancom/edifact/data.rb', line 32 def identifier(value) if @dictionary hash = @dictionary[value] unless hash raise NotFoundInDictionary.new( "Value not found for #{value}. Error in Data: #{self.to_s}" ) else hash[:identifier] end else "" end end |
#to_s ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/eancom/edifact/data.rb', line 47 def to_s "type: #{@type} " \ "length: #{@length} " \ "dictionary: #{@dictionary} " \ "description: #{@description} " \ "required: #{required} " end |
#valid?(key, value) ⇒ Boolean
24 25 26 27 28 29 |
# File 'lib/eancom/edifact/data.rb', line 24 def valid?(key, value) type?(key, value) length?(key, value) required?(key, value) dictionary?(key, value) unless value.empty? end |