sapoci 0.1.9 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/lib/sapoci/document.rb +18 -17
- metadata +9 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: efabe83f29509ca5c589d24c054e6ab09ce5f996
|
4
|
+
data.tar.gz: 9c5a92ecb47b5e254c56fc7c4b57d7cf2dc3d5ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80ab2a1392bf0d77d94ba3789e9bbdf164df64b2bf1c00b1acd75aa53ae1f1a00840bf297a62dc1f993e8f2e34e85375f6eeaf2be08f497c8e59a67da15c1687
|
7
|
+
data.tar.gz: c44563afa1ee922db44602f6018bb534d73ceb991d5efc9695324f38cff28a6a6e8d2792de8e2f409bccfc24661f22d152de0c69282340df75f63e6b8c9aa0bb
|
data/CHANGELOG.md
CHANGED
data/lib/sapoci/document.rb
CHANGED
@@ -6,21 +6,21 @@ require 'sapoci/core_ext'
|
|
6
6
|
|
7
7
|
module SAPOCI
|
8
8
|
# SAPOCI::Document is for parsing and emitting SAP OCI compliant
|
9
|
-
# data.
|
10
|
-
#
|
9
|
+
# data.
|
10
|
+
#
|
11
11
|
# Open a +Document+ by feeding it a string:
|
12
|
-
#
|
12
|
+
#
|
13
13
|
# doc = SAPOCI::Document.from_html("<html>...</html>")
|
14
|
-
#
|
14
|
+
#
|
15
15
|
# Open a +Document+ by parsing a Rails-/Rack compatible +Hash+:
|
16
|
-
#
|
16
|
+
#
|
17
17
|
# doc = SAPOCI::Document.from_params({ "NEW_ITEM-DESCRIPTION"=>{"1"=>"Standard Visitenkarte deutsch 200 St."} })
|
18
18
|
#
|
19
19
|
class Document
|
20
20
|
def initialize(items)
|
21
21
|
@items = items
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
# Create a new document from a HTML string.
|
25
25
|
def self.from_html(html)
|
26
26
|
html_doc = Nokogiri::HTML(html)
|
@@ -28,18 +28,18 @@ module SAPOCI
|
|
28
28
|
yield doc if block_given?
|
29
29
|
doc
|
30
30
|
end
|
31
|
-
|
32
|
-
# Create a new document from a Rails-/Rack-compatible
|
31
|
+
|
32
|
+
# Create a new document from a Rails-/Rack-compatible
|
33
33
|
# params hash.
|
34
34
|
def self.from_params(params)
|
35
35
|
doc = Document.new(parse_params(params))
|
36
36
|
yield doc if block_given?
|
37
37
|
doc
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
# All +Item+ instances.
|
41
41
|
attr_reader :items
|
42
|
-
|
42
|
+
|
43
43
|
# Returns all +items+ as HTML hidden field tags.
|
44
44
|
def to_html(options = {})
|
45
45
|
html = []
|
@@ -48,9 +48,9 @@ module SAPOCI
|
|
48
48
|
end
|
49
49
|
html.join
|
50
50
|
end
|
51
|
-
|
51
|
+
|
52
52
|
private
|
53
|
-
|
53
|
+
|
54
54
|
# Parses a Nokogiri HTML document and returns
|
55
55
|
# +Item+ instances in an array.
|
56
56
|
def self.parse_html(doc)
|
@@ -60,9 +60,10 @@ module SAPOCI
|
|
60
60
|
if /NEW_ITEM-(\w+)\[(\d+)\]/.match(name)
|
61
61
|
property = $1
|
62
62
|
index = $2.to_i - 1
|
63
|
+
method = (property+'=').downcase.to_sym
|
63
64
|
value = item_node.attribute("value").value
|
64
65
|
items[index] = Item.new(index) unless items[index]
|
65
|
-
items[index].send(
|
66
|
+
items[index].send(method, value) if items[index].respond_to?(method)
|
66
67
|
elsif /NEW_ITEM-LONGTEXT_(\d+):132/.match(name)
|
67
68
|
index = $1.to_i - 1
|
68
69
|
value = item_node.attribute("value").value
|
@@ -72,7 +73,7 @@ module SAPOCI
|
|
72
73
|
end
|
73
74
|
items.inject([]) { |memo, (key, value)| memo << value }.sort_by(&:index)
|
74
75
|
end
|
75
|
-
|
76
|
+
|
76
77
|
# Parses a Rails-/Rack-compatible params hash and returns
|
77
78
|
# +Item+ instances in an array.
|
78
79
|
def self.parse_params(params)
|
@@ -83,12 +84,12 @@ module SAPOCI
|
|
83
84
|
oci_values.each do |index, value|
|
84
85
|
index = index.to_i - 1 rescue next
|
85
86
|
property = /NEW_ITEM-(\w+)/.match(oci_name)[1]
|
86
|
-
next if property =~ /LONGTEXT/
|
87
|
+
next if property =~ /LONGTEXT/
|
87
88
|
method = (property+'=').downcase.to_sym
|
88
89
|
items[index] = Item.new(index) unless items[index]
|
89
90
|
items[index].send(method, value) if items[index].respond_to?(method)
|
90
91
|
end if oci_values && oci_values.respond_to?(:each)
|
91
|
-
|
92
|
+
|
92
93
|
# LONGTEXT is a special case because it doesn't follow the conventions
|
93
94
|
# Format is:
|
94
95
|
# NEW_ITEM-LONTEXT_n:132[]
|
@@ -116,6 +117,6 @@ module SAPOCI
|
|
116
117
|
end
|
117
118
|
items.inject([]) { |memo, (key, value)| memo << value }.sort_by(&:index)
|
118
119
|
end
|
119
|
-
|
120
|
+
|
120
121
|
end
|
121
122
|
end
|
metadata
CHANGED
@@ -1,23 +1,20 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sapoci
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oliver Eilhard
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-07-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '1.5'
|
20
|
-
- - "<"
|
21
18
|
- !ruby/object:Gem::Version
|
22
19
|
version: '1.6'
|
23
20
|
type: :runtime
|
@@ -25,9 +22,6 @@ dependencies:
|
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
24
|
- - "~>"
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '1.5'
|
30
|
-
- - "<"
|
31
25
|
- !ruby/object:Gem::Version
|
32
26
|
version: '1.6'
|
33
27
|
- !ruby/object:Gem::Dependency
|
@@ -36,14 +30,14 @@ dependencies:
|
|
36
30
|
requirements:
|
37
31
|
- - "~>"
|
38
32
|
- !ruby/object:Gem::Version
|
39
|
-
version: '1.
|
33
|
+
version: '1.10'
|
40
34
|
type: :development
|
41
35
|
prerelease: false
|
42
36
|
version_requirements: !ruby/object:Gem::Requirement
|
43
37
|
requirements:
|
44
38
|
- - "~>"
|
45
39
|
- !ruby/object:Gem::Version
|
46
|
-
version: '1.
|
40
|
+
version: '1.10'
|
47
41
|
- !ruby/object:Gem::Dependency
|
48
42
|
name: rdoc
|
49
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -64,14 +58,14 @@ dependencies:
|
|
64
58
|
requirements:
|
65
59
|
- - "~>"
|
66
60
|
- !ruby/object:Gem::Version
|
67
|
-
version: '10.
|
61
|
+
version: '10.4'
|
68
62
|
type: :development
|
69
63
|
prerelease: false
|
70
64
|
version_requirements: !ruby/object:Gem::Requirement
|
71
65
|
requirements:
|
72
66
|
- - "~>"
|
73
67
|
- !ruby/object:Gem::Version
|
74
|
-
version: '10.
|
68
|
+
version: '10.4'
|
75
69
|
description: Ruby library and Rails plugin for punchout via SAP OCI protocol.
|
76
70
|
email:
|
77
71
|
- oliver.eilhard@gmail.com
|
@@ -102,9 +96,9 @@ require_paths:
|
|
102
96
|
- lib
|
103
97
|
required_ruby_version: !ruby/object:Gem::Requirement
|
104
98
|
requirements:
|
105
|
-
- - "
|
99
|
+
- - "~>"
|
106
100
|
- !ruby/object:Gem::Version
|
107
|
-
version: '
|
101
|
+
version: '2.2'
|
108
102
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
103
|
requirements:
|
110
104
|
- - ">="
|
@@ -112,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
112
106
|
version: 1.3.6
|
113
107
|
requirements: []
|
114
108
|
rubyforge_project:
|
115
|
-
rubygems_version: 2.
|
109
|
+
rubygems_version: 2.4.6
|
116
110
|
signing_key:
|
117
111
|
specification_version: 4
|
118
112
|
summary: SAP OCI enables users to parse SAP OCI compliant data from online shops.
|