Class: Secretariat::Attachment
- Inherits:
-
Struct
- Object
- Struct
- Secretariat::Attachment
- Includes:
- Versioner
- Defined in:
- lib/secretariat/attachment.rb
Instance Attribute Summary collapse
-
#base64 ⇒ Object
Returns the value of attribute base64.
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#type_code ⇒ Object
Returns the value of attribute type_code.
Instance Method Summary collapse
- #errors ⇒ Object
- #mime_code ⇒ Object
- #to_xml(xml, attachment_index, version: 2, validate: true) ⇒ Object
- #valid? ⇒ Boolean
Methods included from Versioner
Instance Attribute Details
#base64 ⇒ Object
Returns the value of attribute base64
22 23 24 |
# File 'lib/secretariat/attachment.rb', line 22 def base64 @base64 end |
#filename ⇒ Object
Returns the value of attribute filename
22 23 24 |
# File 'lib/secretariat/attachment.rb', line 22 def filename @filename end |
#type_code ⇒ Object
Returns the value of attribute type_code
22 23 24 |
# File 'lib/secretariat/attachment.rb', line 22 def type_code @type_code end |
Instance Method Details
#errors ⇒ Object
31 32 33 |
# File 'lib/secretariat/attachment.rb', line 31 def errors @errors end |
#mime_code ⇒ Object
60 61 62 63 64 65 |
# File 'lib/secretariat/attachment.rb', line 60 def mime_code type_for = MIME::Types.type_for(filename).first return if type_for.nil? type_for.content_type end |
#to_xml(xml, attachment_index, version: 2, validate: true) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/secretariat/attachment.rb', line 67 def to_xml(xml, , version: 2, validate: true) if validate && !valid? pp errors raise ValidationError.new("Attachment #{attachment_index} is invalid", errors) end xml['ram'].AdditionalReferencedDocument do xml['ram'].IssuerAssignedID filename xml['ram'].TypeCode type_code xml['ram'].Name filename xml['ram'].AttachmentBinaryObject(mimeCode: mime_code, filename: filename) do xml.text(base64) end end end |
#valid? ⇒ Boolean
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/secretariat/attachment.rb', line 35 def valid? @errors = [] @errors << "the attribute filename needs to be present" if filename.nil? || filename == '' @errors << "the attribute type_code needs to be present" if type_code.nil? || type_code == '' @errors << "the attribute base64 needs to be present" if base64.nil? || base64 == '' if type_code.to_i != 916 @errors << "we only support type_code 916" return false end if mime_code.nil? @errors << "cannot determine content type for filename: #{filename}" return false end if !ALLOWED_MIME_TYPES.include?(mime_code) @errors << "the mime_code '#{mime_code}' is not allowed" return false end return true end |