Class: OpenRosa::Manifest
- Inherits:
-
Object
- Object
- OpenRosa::Manifest
- Defined in:
- lib/open_rosa/manifest.rb
Overview
Represents a manifest of media files associated with a form. The manifest lists all supporting files (images, audio, video, entity lists) that need to be downloaded along with the form definition.
Instance Attribute Summary collapse
-
#media_files ⇒ Object
readonly
Returns the value of attribute media_files.
Instance Method Summary collapse
-
#add_media_file(media_file) ⇒ Manifest
Adds a media file to the manifest.
-
#count ⇒ Integer
Count of media files in the manifest.
-
#empty? ⇒ Boolean
Check if the manifest is empty.
-
#initialize(media_files: []) ⇒ Manifest
constructor
Creates a new Manifest.
-
#to_xml ⇒ String
Generates OpenRosa manifest XML.
Constructor Details
#initialize(media_files: []) ⇒ Manifest
Creates a new Manifest
38 39 40 |
# File 'lib/open_rosa/manifest.rb', line 38 def initialize(media_files: []) @media_files = media_files end |
Instance Attribute Details
#media_files ⇒ Object (readonly)
Returns the value of attribute media_files.
33 34 35 |
# File 'lib/open_rosa/manifest.rb', line 33 def media_files @media_files end |
Instance Method Details
#add_media_file(media_file) ⇒ Manifest
Adds a media file to the manifest
46 47 48 49 |
# File 'lib/open_rosa/manifest.rb', line 46 def add_media_file(media_file) @media_files << media_file self end |
#count ⇒ Integer
Count of media files in the manifest
76 77 78 |
# File 'lib/open_rosa/manifest.rb', line 76 def count media_files.count end |
#empty? ⇒ Boolean
Check if the manifest is empty
69 70 71 |
# File 'lib/open_rosa/manifest.rb', line 69 def empty? media_files.empty? end |
#to_xml ⇒ String
Generates OpenRosa manifest XML
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/open_rosa/manifest.rb', line 54 def to_xml builder = Nokogiri::XML::Builder.new(encoding: "UTF-8") do |xml| xml.manifest(xmlns: "http://openrosa.org/xforms/xformsManifest") do media_files.each do |media_file| build_media_file(xml, media_file) end end end builder.to_xml end |