Class: SAPOCI::Document

Inherits:
Object show all
Defined in:
lib/sapoci/document.rb

Overview

SAPOCI::Document is for parsing and emitting SAP OCI compliant data.

Open a Document by feeding it a string:

doc = SAPOCI::Document.from_html("<html>...</html>")

Open a Document by parsing a Rails-/Rack compatible Hash:

doc = SAPOCI::Document.from_params({ "NEW_ITEM-DESCRIPTION"=>{"1"=>"Standard Visitenkarte deutsch 200 St."} })

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(items) ⇒ Document

Returns a new instance of Document.



20
21
22
# File 'lib/sapoci/document.rb', line 20

def initialize(items)
  @items = items
end

Instance Attribute Details

#itemsObject (readonly)

All Item instances.



41
42
43
# File 'lib/sapoci/document.rb', line 41

def items
  @items
end

Class Method Details

.from_html(html) {|doc| ... } ⇒ Object

Create a new document from a HTML string.

Yields:

  • (doc)


25
26
27
28
29
30
# File 'lib/sapoci/document.rb', line 25

def self.from_html(html)
  html_doc = Nokogiri::HTML(html)
  doc = Document.new(parse_html(html_doc))
  yield doc if block_given?
  doc
end

.from_params(params) {|doc| ... } ⇒ Object

Create a new document from a Rails-/Rack-compatible params hash.

Yields:

  • (doc)


34
35
36
37
38
# File 'lib/sapoci/document.rb', line 34

def self.from_params(params)
  doc = Document.new(parse_params(params))
  yield doc if block_given?
  doc
end

Instance Method Details

#to_html(options = {}) ⇒ Object

Returns all items as HTML hidden field tags.



44
45
46
47
48
49
50
# File 'lib/sapoci/document.rb', line 44

def to_html(options = {})
  html = []
  self.items.each do |item|
    html << item.to_html(options)
  end
  html.join
end