Class: OpenRosa::Manifest

Inherits:
Object
  • Object
show all
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.

Examples:

Create a manifest with media files

manifest = OpenRosa::Manifest.new
manifest.add_media_file(
  OpenRosa::MediaFile.new(
    filename: "images/logo.png",
    hash: "md5:abc123",
    download_url: "https://example.com/media/logo.png"
  )
)
xml = manifest.to_xml

Create a manifest with entity list

manifest = OpenRosa::Manifest.new
manifest.add_media_file(
  OpenRosa::MediaFile.new(
    filename: "entities.csv",
    hash: "md5:xyz789",
    download_url: "https://example.com/entities.csv",
    type: "entityList",
    integrity_url: "https://example.com/entities/integrity"
  )
)

Instance Attribute Summary collapse

Instance Method Summary collapse

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_filesObject (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

#countInteger

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_xmlString

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