gobl 0.1.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/data/tax/CO.json +420 -0
- data/data/tax/ES.json +61 -0
- data/lib/ext/hashme.rb +28 -0
- data/lib/gobl/bill/advances.rb +1 -77
- data/lib/gobl/bill/charge.rb +11 -65
- data/lib/gobl/bill/delivery.rb +5 -47
- data/lib/gobl/bill/discount.rb +11 -65
- data/lib/gobl/bill/exchange_rates.rb +1 -77
- data/lib/gobl/bill/invoice.rb +28 -104
- data/lib/gobl/bill/invoice_type.rb +3 -134
- data/lib/gobl/bill/line.rb +13 -65
- data/lib/gobl/bill/line_charge.rb +5 -47
- data/lib/gobl/bill/line_discount.rb +5 -47
- data/lib/gobl/bill/ordering.rb +2 -38
- data/lib/gobl/bill/outlay.rb +11 -59
- data/lib/gobl/bill/payment.rb +5 -47
- data/lib/gobl/bill/preceding.rb +12 -62
- data/lib/gobl/bill/scheme_keys.rb +1 -77
- data/lib/gobl/bill/tax.rb +4 -44
- data/lib/gobl/bill/totals.rb +17 -71
- data/lib/gobl/cal/date.rb +1 -90
- data/lib/gobl/cal/period.rb +5 -41
- data/lib/gobl/currency/code.rb +3 -134
- data/lib/gobl/currency/exchange_rate.rb +5 -41
- data/lib/gobl/document.rb +1 -58
- data/lib/gobl/dsig/digest.rb +5 -41
- data/lib/gobl/dsig/signature.rb +1 -90
- data/lib/gobl/enum.rb +81 -0
- data/lib/gobl/envelope.rb +9 -48
- data/lib/gobl/header.rb +10 -56
- data/lib/gobl/i18n/string.rb +1 -58
- data/lib/gobl/l10n/code.rb +1 -90
- data/lib/gobl/l10n/country_code.rb +3 -134
- data/lib/gobl/map.rb +62 -0
- data/lib/gobl/note/message.rb +5 -44
- data/lib/gobl/num/amount.rb +6 -35
- data/lib/gobl/object.rb +21 -0
- data/lib/gobl/operations.rb +3 -3
- data/lib/gobl/org/address.rb +18 -80
- data/lib/gobl/org/code.rb +1 -90
- data/lib/gobl/org/coordinates.rb +5 -47
- data/lib/gobl/org/email.rb +6 -47
- data/lib/gobl/org/inbox.rb +8 -50
- data/lib/gobl/org/item.rb +13 -65
- data/lib/gobl/org/item_code.rb +4 -41
- data/lib/gobl/org/key.rb +1 -90
- data/lib/gobl/org/meta.rb +1 -58
- data/lib/gobl/org/name.rb +12 -62
- data/lib/gobl/org/note.rb +6 -47
- data/lib/gobl/org/note_key.rb +3 -134
- data/lib/gobl/org/party.rb +14 -71
- data/lib/gobl/org/person.rb +9 -56
- data/lib/gobl/org/registration.rb +9 -59
- data/lib/gobl/org/source_key.rb +3 -134
- data/lib/gobl/org/tax_identity.rb +8 -53
- data/lib/gobl/org/telephone.rb +5 -44
- data/lib/gobl/org/unit.rb +1 -136
- data/lib/gobl/pay/advance.rb +11 -59
- data/lib/gobl/pay/card.rb +5 -41
- data/lib/gobl/pay/credit_transfer.rb +6 -50
- data/lib/gobl/pay/direct_debit.rb +4 -44
- data/lib/gobl/pay/due_date.rb +8 -50
- data/lib/gobl/pay/instructions.rb +11 -62
- data/lib/gobl/pay/method_key.rb +3 -134
- data/lib/gobl/pay/online.rb +4 -41
- data/lib/gobl/pay/term_key.rb +3 -134
- data/lib/gobl/pay/terms.rb +6 -47
- data/lib/gobl/stamp.rb +5 -41
- data/lib/gobl/struct.rb +15 -15
- data/lib/gobl/tax/category.rb +9 -50
- data/lib/gobl/tax/category_total.rb +11 -53
- data/lib/gobl/tax/combo.rb +6 -47
- data/lib/gobl/tax/localities.rb +1 -77
- data/lib/gobl/tax/locality.rb +6 -44
- data/lib/gobl/tax/rate.rb +8 -47
- data/lib/gobl/tax/rate_total.rb +9 -50
- data/lib/gobl/tax/rate_total_surcharge.rb +5 -41
- data/lib/gobl/tax/rate_value.rb +6 -47
- data/lib/gobl/tax/region.rb +12 -56
- data/lib/gobl/tax/scheme.rb +8 -50
- data/lib/gobl/tax/schemes.rb +1 -77
- data/lib/gobl/tax/set.rb +1 -77
- data/lib/gobl/tax/total.rb +4 -41
- data/lib/gobl/uuid/uuid.rb +1 -90
- data/lib/gobl/value.rb +58 -0
- data/lib/gobl/version.rb +1 -1
- data/lib/gobl.rb +3 -1
- data/lib/gobl_extensions/document_helper.rb +3 -3
- data/lib/gobl_extensions/envelope_helper.rb +5 -0
- data/lib/gobl_extensions/i18n/value_keys_helper.rb +3 -3
- data/lib/gobl_extensions/tax/region_helper.rb +3 -9
- metadata +12 -35
- data/lib/gobl/types.rb +0 -17
data/lib/gobl/org/address.rb
CHANGED
@@ -9,148 +9,86 @@
|
|
9
9
|
module GOBL
|
10
10
|
module Org
|
11
11
|
# Address defines a globally acceptable set of attributes that describes a postal or fiscal address.
|
12
|
-
class Address < GOBL::
|
12
|
+
class Address < GOBL::Object
|
13
13
|
# The Schema ID of the GOBL Address structure
|
14
14
|
SCHEMA_ID = 'https://gobl.org/draft-0/org/address'
|
15
15
|
|
16
16
|
# @!attribute [r] uuid
|
17
17
|
# Internal ID used to identify the party inside a document.
|
18
18
|
# @return [GOBL::UUID::UUID]
|
19
|
-
|
19
|
+
property :uuid, GOBL::UUID::UUID
|
20
20
|
|
21
21
|
# @!attribute [r] label
|
22
22
|
# Useful identifier, such as home, work, etc.
|
23
23
|
# @return [String]
|
24
|
-
|
24
|
+
property :label, String
|
25
25
|
|
26
26
|
# @!attribute [r] po_box
|
27
27
|
# Box number or code for the post office box located at the address.
|
28
28
|
# @return [String]
|
29
|
-
|
29
|
+
property :po_box, String
|
30
30
|
|
31
31
|
# @!attribute [r] num
|
32
32
|
# House or building number in the street.
|
33
33
|
# @return [String]
|
34
|
-
|
34
|
+
property :num, String
|
35
35
|
|
36
36
|
# @!attribute [r] floor
|
37
37
|
# Floor number within the building.
|
38
38
|
# @return [String]
|
39
|
-
|
39
|
+
property :floor, String
|
40
40
|
|
41
41
|
# @!attribute [r] block
|
42
42
|
# Block number within the building.
|
43
43
|
# @return [String]
|
44
|
-
|
44
|
+
property :block, String
|
45
45
|
|
46
46
|
# @!attribute [r] door
|
47
47
|
# Door number within the building.
|
48
48
|
# @return [String]
|
49
|
-
|
49
|
+
property :door, String
|
50
50
|
|
51
51
|
# @!attribute [r] street
|
52
52
|
# First line of street.
|
53
53
|
# @return [String]
|
54
|
-
|
54
|
+
property :street, String
|
55
55
|
|
56
56
|
# @!attribute [r] street_extra
|
57
57
|
# Additional street address details.
|
58
58
|
# @return [String]
|
59
|
-
|
59
|
+
property :street_extra, String
|
60
60
|
|
61
61
|
# @!attribute [r] locality
|
62
62
|
# The village, town, district, or city.
|
63
63
|
# @return [String]
|
64
|
-
|
64
|
+
property :locality, String
|
65
|
+
validates :locality, presence: true
|
65
66
|
|
66
67
|
# @!attribute [r] region
|
67
68
|
# Province, County, or State.
|
68
69
|
# @return [String]
|
69
|
-
|
70
|
+
property :region, String
|
71
|
+
validates :region, presence: true
|
70
72
|
|
71
73
|
# @!attribute [r] code
|
72
74
|
# Post or ZIP code.
|
73
75
|
# @return [String]
|
74
|
-
|
76
|
+
property :code, String
|
75
77
|
|
76
78
|
# @!attribute [r] country
|
77
79
|
# ISO country code.
|
78
80
|
# @return [GOBL::L10n::CountryCode]
|
79
|
-
|
81
|
+
property :country, GOBL::L10n::CountryCode
|
80
82
|
|
81
83
|
# @!attribute [r] coords
|
82
84
|
# When the postal address is not sufficient, coordinates help locate the address more precisely.
|
83
85
|
# @return [GOBL::Org::Coordinates]
|
84
|
-
|
86
|
+
property :coords, GOBL::Org::Coordinates
|
85
87
|
|
86
88
|
# @!attribute [r] meta
|
87
89
|
# Any additional semi-structure details about the address.
|
88
90
|
# @return [GOBL::Org::Meta]
|
89
|
-
|
90
|
-
|
91
|
-
# Creates a new object from a hash of GOBL data
|
92
|
-
#
|
93
|
-
# @param data [Hash] a hash of GOBL data
|
94
|
-
#
|
95
|
-
# @return [Address] the object created from the given data
|
96
|
-
def self.from_gobl!(data)
|
97
|
-
data = GOBL::Types::Hash[data]
|
98
|
-
|
99
|
-
new(
|
100
|
-
uuid: data['uuid'] ? GOBL::UUID::UUID.from_gobl!(data['uuid']) : nil,
|
101
|
-
label: data['label'],
|
102
|
-
po_box: data['po_box'],
|
103
|
-
num: data['num'],
|
104
|
-
floor: data['floor'],
|
105
|
-
block: data['block'],
|
106
|
-
door: data['door'],
|
107
|
-
street: data['street'],
|
108
|
-
street_extra: data['street_extra'],
|
109
|
-
locality: data['locality'],
|
110
|
-
region: data['region'],
|
111
|
-
code: data['code'],
|
112
|
-
country: data['country'] ? GOBL::L10n::CountryCode.from_gobl!(data['country']) : nil,
|
113
|
-
coords: data['coords'] ? GOBL::Org::Coordinates.from_gobl!(data['coords']) : nil,
|
114
|
-
meta: data['meta'] ? GOBL::Org::Meta.from_gobl!(data['meta']) : nil
|
115
|
-
)
|
116
|
-
end
|
117
|
-
|
118
|
-
# Returns a hash of GOBL data representing the current object
|
119
|
-
#
|
120
|
-
# @return [Hash] the array of GOBL data that represents the current object
|
121
|
-
def to_gobl
|
122
|
-
{
|
123
|
-
'uuid' => attributes[:uuid]&.to_gobl,
|
124
|
-
'label' => attributes[:label],
|
125
|
-
'po_box' => attributes[:po_box],
|
126
|
-
'num' => attributes[:num],
|
127
|
-
'floor' => attributes[:floor],
|
128
|
-
'block' => attributes[:block],
|
129
|
-
'door' => attributes[:door],
|
130
|
-
'street' => attributes[:street],
|
131
|
-
'street_extra' => attributes[:street_extra],
|
132
|
-
'locality' => attributes[:locality],
|
133
|
-
'region' => attributes[:region],
|
134
|
-
'code' => attributes[:code],
|
135
|
-
'country' => attributes[:country]&.to_gobl,
|
136
|
-
'coords' => attributes[:coords]&.to_gobl,
|
137
|
-
'meta' => attributes[:meta]&.to_gobl
|
138
|
-
}.compact
|
139
|
-
end
|
140
|
-
|
141
|
-
# @!method self.new(attrs)
|
142
|
-
#
|
143
|
-
# Returns a {Address} object from a given hash of attributes. Nested
|
144
|
-
# attributes are supported: the constructor will instantiate the proper GOBL
|
145
|
-
# objects when nested hashes or arrays are given as part of the `attrs`
|
146
|
-
# parameter.
|
147
|
-
#
|
148
|
-
# The `new` method will only allow to create a new object if all attributes
|
149
|
-
# marked as mandatory and not calculated in the JSON schema are provided.
|
150
|
-
#
|
151
|
-
# @param attrs [Hash] the hash of attributes
|
152
|
-
#
|
153
|
-
# @return [Address] the object corresponding to the given input
|
91
|
+
property :meta, GOBL::Org::Meta
|
154
92
|
end
|
155
93
|
end
|
156
94
|
end
|
data/lib/gobl/org/code.rb
CHANGED
@@ -9,98 +9,9 @@
|
|
9
9
|
module GOBL
|
10
10
|
module Org
|
11
11
|
# Short upper-case identifier.
|
12
|
-
class Code < GOBL::
|
12
|
+
class Code < GOBL::Value
|
13
13
|
# The Schema ID of the GOBL Code structure
|
14
14
|
SCHEMA_ID = 'https://gobl.org/draft-0/org/code'
|
15
|
-
|
16
|
-
attribute :_value, GOBL::Types::String
|
17
|
-
private :_value
|
18
|
-
|
19
|
-
# Creates a new object from a GOBL value
|
20
|
-
#
|
21
|
-
# @param data [String] the GOBL value
|
22
|
-
#
|
23
|
-
# @return [Code] the object created from the given data
|
24
|
-
def self.from_gobl!(data)
|
25
|
-
new(_value: data)
|
26
|
-
end
|
27
|
-
|
28
|
-
# Returns a GOBL value representing the current object
|
29
|
-
#
|
30
|
-
# @return [String] the GOBL value that represents the current object
|
31
|
-
def to_gobl
|
32
|
-
_value
|
33
|
-
end
|
34
|
-
|
35
|
-
# Returns a {Code} that corresponds to a given object. The object can be a
|
36
|
-
# `Symbol`, a `String` or anything coercible into one (via `#to_s`).
|
37
|
-
#
|
38
|
-
# @param object [Symbol, String, #to_s] the value of the object.
|
39
|
-
#
|
40
|
-
# @return [Code] the object corresponding to the given value.
|
41
|
-
#
|
42
|
-
# @example Instantiating from a symbol
|
43
|
-
# code = GOBL::Org::Code.new(:value)
|
44
|
-
#
|
45
|
-
# @example Instantiating from a string
|
46
|
-
# code = GOBL::Org::Code.new('value')
|
47
|
-
def self.new(object)
|
48
|
-
case object
|
49
|
-
when Hash, self # internal use, not to be used in public calls
|
50
|
-
super
|
51
|
-
when Symbol
|
52
|
-
new object.to_s
|
53
|
-
else
|
54
|
-
super _value: object.to_s
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
# Returns the string representation of the current object
|
59
|
-
#
|
60
|
-
# @return [String] the string representation of the current object
|
61
|
-
def to_s
|
62
|
-
_value.to_s
|
63
|
-
end
|
64
|
-
|
65
|
-
# Returns the symbol representation of the current object
|
66
|
-
#
|
67
|
-
# @return [Symbol] the symbol representation of the current object
|
68
|
-
def to_sym
|
69
|
-
to_s.parameterize.underscore.to_sym
|
70
|
-
end
|
71
|
-
|
72
|
-
# Returns whether the current object is equivalent to a given one. In addition
|
73
|
-
# to {Code} objects, the current object can be compared to a `Symbol`, a
|
74
|
-
# `String` or anything coercible into one (via `#to_s`)
|
75
|
-
#
|
76
|
-
# @param other [Code, Symbol, String, #to_s] the other object to compare to
|
77
|
-
#
|
78
|
-
# @return [Boolean] `true` if the objects are equivalent, `false` otherwise
|
79
|
-
#
|
80
|
-
# @example Comparing to another {Code} object
|
81
|
-
# code = GOBL::Org::Code.new('value')
|
82
|
-
# code == GOBL::Org::Code.new('value') #=> true
|
83
|
-
# code == GOBL::Org::Code.new('other') #=> false
|
84
|
-
#
|
85
|
-
# @example Comparing to a string
|
86
|
-
# code = GOBL::Org::Code.new('value')
|
87
|
-
# code == 'value' #=> true
|
88
|
-
# code == 'other' #=> false
|
89
|
-
#
|
90
|
-
# @example Comparing to a symbol
|
91
|
-
# code = GOBL::Org::Code.new('value')
|
92
|
-
# code == :value #=> true
|
93
|
-
# code == :other #=> false
|
94
|
-
def ==(other)
|
95
|
-
case other
|
96
|
-
when self.class
|
97
|
-
super
|
98
|
-
when Symbol
|
99
|
-
to_sym == other
|
100
|
-
else
|
101
|
-
to_s == other.to_s
|
102
|
-
end
|
103
|
-
end
|
104
15
|
end
|
105
16
|
end
|
106
17
|
end
|
data/lib/gobl/org/coordinates.rb
CHANGED
@@ -9,71 +9,29 @@
|
|
9
9
|
module GOBL
|
10
10
|
module Org
|
11
11
|
# Coordinates describes an exact geographical location in the world.
|
12
|
-
class Coordinates < GOBL::
|
12
|
+
class Coordinates < GOBL::Object
|
13
13
|
# The Schema ID of the GOBL Coordinates structure
|
14
14
|
SCHEMA_ID = 'https://gobl.org/draft-0/org/coordinates'
|
15
15
|
|
16
16
|
# @!attribute [r] lat
|
17
17
|
# Decimal latitude coordinate.
|
18
18
|
# @return [Float]
|
19
|
-
|
19
|
+
property :lat, Float
|
20
20
|
|
21
21
|
# @!attribute [r] lon
|
22
22
|
# Decimal longitude coordinate.
|
23
23
|
# @return [Float]
|
24
|
-
|
24
|
+
property :lon, Float
|
25
25
|
|
26
26
|
# @!attribute [r] w3w
|
27
27
|
# Text coordinates compose of three words.
|
28
28
|
# @return [String]
|
29
|
-
|
29
|
+
property :w3w, String
|
30
30
|
|
31
31
|
# @!attribute [r] geohash
|
32
32
|
# Single string coordinate based on geohash standard.
|
33
33
|
# @return [String]
|
34
|
-
|
35
|
-
|
36
|
-
# Creates a new object from a hash of GOBL data
|
37
|
-
#
|
38
|
-
# @param data [Hash] a hash of GOBL data
|
39
|
-
#
|
40
|
-
# @return [Coordinates] the object created from the given data
|
41
|
-
def self.from_gobl!(data)
|
42
|
-
data = GOBL::Types::Hash[data]
|
43
|
-
|
44
|
-
new(
|
45
|
-
lat: data['lat'],
|
46
|
-
lon: data['lon'],
|
47
|
-
w3w: data['w3w'],
|
48
|
-
geohash: data['geohash']
|
49
|
-
)
|
50
|
-
end
|
51
|
-
|
52
|
-
# Returns a hash of GOBL data representing the current object
|
53
|
-
#
|
54
|
-
# @return [Hash] the array of GOBL data that represents the current object
|
55
|
-
def to_gobl
|
56
|
-
{
|
57
|
-
'lat' => attributes[:lat],
|
58
|
-
'lon' => attributes[:lon],
|
59
|
-
'w3w' => attributes[:w3w],
|
60
|
-
'geohash' => attributes[:geohash]
|
61
|
-
}.compact
|
62
|
-
end
|
63
|
-
|
64
|
-
# @!method self.new(attrs)
|
65
|
-
#
|
66
|
-
# Returns a {Coordinates} object from a given hash of attributes. Nested
|
67
|
-
# attributes are supported: the constructor will instantiate the proper GOBL
|
68
|
-
# objects when nested hashes or arrays are given as part of the `attrs`
|
69
|
-
# parameter.
|
70
|
-
#
|
71
|
-
# The `new` method will only allow to create a new object if all attributes
|
72
|
-
# marked as mandatory and not calculated in the JSON schema are provided.
|
73
|
-
#
|
74
|
-
# @param attrs [Hash] the hash of attributes
|
75
|
-
#
|
76
|
-
# @return [Coordinates] the object corresponding to the given input
|
34
|
+
property :geohash, String
|
77
35
|
end
|
78
36
|
end
|
79
37
|
end
|
data/lib/gobl/org/email.rb
CHANGED
@@ -9,71 +9,30 @@
|
|
9
9
|
module GOBL
|
10
10
|
module Org
|
11
11
|
# Email describes the electronic mailing details.
|
12
|
-
class Email < GOBL::
|
12
|
+
class Email < GOBL::Object
|
13
13
|
# The Schema ID of the GOBL Email structure
|
14
14
|
SCHEMA_ID = 'https://gobl.org/draft-0/org/email'
|
15
15
|
|
16
16
|
# @!attribute [r] uuid
|
17
17
|
# Unique identity code
|
18
18
|
# @return [GOBL::UUID::UUID]
|
19
|
-
|
19
|
+
property :uuid, GOBL::UUID::UUID
|
20
20
|
|
21
21
|
# @!attribute [r] label
|
22
22
|
# Identifier for the email.
|
23
23
|
# @return [String]
|
24
|
-
|
24
|
+
property :label, String
|
25
25
|
|
26
26
|
# @!attribute [r] addr
|
27
27
|
# Electronic mailing address.
|
28
28
|
# @return [String]
|
29
|
-
|
29
|
+
property :addr, String
|
30
|
+
validates :addr, presence: true
|
30
31
|
|
31
32
|
# @!attribute [r] meta
|
32
33
|
# Additional fields.
|
33
34
|
# @return [GOBL::Org::Meta]
|
34
|
-
|
35
|
-
|
36
|
-
# Creates a new object from a hash of GOBL data
|
37
|
-
#
|
38
|
-
# @param data [Hash] a hash of GOBL data
|
39
|
-
#
|
40
|
-
# @return [Email] the object created from the given data
|
41
|
-
def self.from_gobl!(data)
|
42
|
-
data = GOBL::Types::Hash[data]
|
43
|
-
|
44
|
-
new(
|
45
|
-
uuid: data['uuid'] ? GOBL::UUID::UUID.from_gobl!(data['uuid']) : nil,
|
46
|
-
label: data['label'],
|
47
|
-
addr: data['addr'],
|
48
|
-
meta: data['meta'] ? GOBL::Org::Meta.from_gobl!(data['meta']) : nil
|
49
|
-
)
|
50
|
-
end
|
51
|
-
|
52
|
-
# Returns a hash of GOBL data representing the current object
|
53
|
-
#
|
54
|
-
# @return [Hash] the array of GOBL data that represents the current object
|
55
|
-
def to_gobl
|
56
|
-
{
|
57
|
-
'uuid' => attributes[:uuid]&.to_gobl,
|
58
|
-
'label' => attributes[:label],
|
59
|
-
'addr' => attributes[:addr],
|
60
|
-
'meta' => attributes[:meta]&.to_gobl
|
61
|
-
}.compact
|
62
|
-
end
|
63
|
-
|
64
|
-
# @!method self.new(attrs)
|
65
|
-
#
|
66
|
-
# Returns a {Email} object from a given hash of attributes. Nested
|
67
|
-
# attributes are supported: the constructor will instantiate the proper GOBL
|
68
|
-
# objects when nested hashes or arrays are given as part of the `attrs`
|
69
|
-
# parameter.
|
70
|
-
#
|
71
|
-
# The `new` method will only allow to create a new object if all attributes
|
72
|
-
# marked as mandatory and not calculated in the JSON schema are provided.
|
73
|
-
#
|
74
|
-
# @param attrs [Hash] the hash of attributes
|
75
|
-
#
|
76
|
-
# @return [Email] the object corresponding to the given input
|
35
|
+
property :meta, GOBL::Org::Meta
|
77
36
|
end
|
78
37
|
end
|
79
38
|
end
|
data/lib/gobl/org/inbox.rb
CHANGED
@@ -9,78 +9,36 @@
|
|
9
9
|
module GOBL
|
10
10
|
module Org
|
11
11
|
# Inbox is used to store data about a connection with a service that is responsible for potentially receiving copies of GOBL envelopes or other document formats defined locally.
|
12
|
-
class Inbox < GOBL::
|
12
|
+
class Inbox < GOBL::Object
|
13
13
|
# The Schema ID of the GOBL Inbox structure
|
14
14
|
SCHEMA_ID = 'https://gobl.org/draft-0/org/inbox'
|
15
15
|
|
16
16
|
# @!attribute [r] uuid
|
17
17
|
# Unique ID. Useful if inbox is stored in a database.
|
18
18
|
# @return [GOBL::UUID::UUID]
|
19
|
-
|
19
|
+
property :uuid, GOBL::UUID::UUID
|
20
20
|
|
21
21
|
# @!attribute [r] key
|
22
22
|
# Type of inbox being defined.
|
23
23
|
# @return [GOBL::Org::Key]
|
24
|
-
|
24
|
+
property :key, GOBL::Org::Key
|
25
|
+
validates :key, presence: true
|
25
26
|
|
26
27
|
# @!attribute [r] role
|
27
28
|
# Role assigned to this inbox that may be relevant for the consumer.
|
28
29
|
# @return [GOBL::Org::Key]
|
29
|
-
|
30
|
+
property :role, GOBL::Org::Key
|
30
31
|
|
31
32
|
# @!attribute [r] name
|
32
33
|
# Human name for the inbox.
|
33
34
|
# @return [String]
|
34
|
-
|
35
|
+
property :name, String
|
35
36
|
|
36
37
|
# @!attribute [r] code
|
37
38
|
# Actual Code or ID that identifies the Inbox.
|
38
39
|
# @return [String]
|
39
|
-
|
40
|
-
|
41
|
-
# Creates a new object from a hash of GOBL data
|
42
|
-
#
|
43
|
-
# @param data [Hash] a hash of GOBL data
|
44
|
-
#
|
45
|
-
# @return [Inbox] the object created from the given data
|
46
|
-
def self.from_gobl!(data)
|
47
|
-
data = GOBL::Types::Hash[data]
|
48
|
-
|
49
|
-
new(
|
50
|
-
uuid: data['uuid'] ? GOBL::UUID::UUID.from_gobl!(data['uuid']) : nil,
|
51
|
-
key: GOBL::Org::Key.from_gobl!(data['key']),
|
52
|
-
role: data['role'] ? GOBL::Org::Key.from_gobl!(data['role']) : nil,
|
53
|
-
name: data['name'],
|
54
|
-
code: data['code']
|
55
|
-
)
|
56
|
-
end
|
57
|
-
|
58
|
-
# Returns a hash of GOBL data representing the current object
|
59
|
-
#
|
60
|
-
# @return [Hash] the array of GOBL data that represents the current object
|
61
|
-
def to_gobl
|
62
|
-
{
|
63
|
-
'uuid' => attributes[:uuid]&.to_gobl,
|
64
|
-
'key' => attributes[:key]&.to_gobl,
|
65
|
-
'role' => attributes[:role]&.to_gobl,
|
66
|
-
'name' => attributes[:name],
|
67
|
-
'code' => attributes[:code]
|
68
|
-
}.compact
|
69
|
-
end
|
70
|
-
|
71
|
-
# @!method self.new(attrs)
|
72
|
-
#
|
73
|
-
# Returns a {Inbox} object from a given hash of attributes. Nested
|
74
|
-
# attributes are supported: the constructor will instantiate the proper GOBL
|
75
|
-
# objects when nested hashes or arrays are given as part of the `attrs`
|
76
|
-
# parameter.
|
77
|
-
#
|
78
|
-
# The `new` method will only allow to create a new object if all attributes
|
79
|
-
# marked as mandatory and not calculated in the JSON schema are provided.
|
80
|
-
#
|
81
|
-
# @param attrs [Hash] the hash of attributes
|
82
|
-
#
|
83
|
-
# @return [Inbox] the object corresponding to the given input
|
40
|
+
property :code, String
|
41
|
+
validates :code, presence: true
|
84
42
|
end
|
85
43
|
end
|
86
44
|
end
|
data/lib/gobl/org/item.rb
CHANGED
@@ -9,113 +9,61 @@
|
|
9
9
|
module GOBL
|
10
10
|
module Org
|
11
11
|
# Item is used to describe a single product or service.
|
12
|
-
class Item < GOBL::
|
12
|
+
class Item < GOBL::Object
|
13
13
|
# The Schema ID of the GOBL Item structure
|
14
14
|
SCHEMA_ID = 'https://gobl.org/draft-0/org/item'
|
15
15
|
|
16
16
|
# @!attribute [r] uuid
|
17
17
|
# Unique identify of this item independent of the Supplier IDs
|
18
18
|
# @return [GOBL::UUID::UUID]
|
19
|
-
|
19
|
+
property :uuid, GOBL::UUID::UUID
|
20
20
|
|
21
21
|
# @!attribute [r] ref
|
22
22
|
# Primary reference code that identifies this item. Additional codes can be provided in the 'codes' field.
|
23
23
|
# @return [String]
|
24
|
-
|
24
|
+
property :ref, String
|
25
25
|
|
26
26
|
# @!attribute [r] name
|
27
27
|
# Brief name of the item
|
28
28
|
# @return [String]
|
29
|
-
|
29
|
+
property :name, String
|
30
|
+
validates :name, presence: true
|
30
31
|
|
31
32
|
# @!attribute [r] desc
|
32
33
|
# Detailed description
|
33
34
|
# @return [String]
|
34
|
-
|
35
|
+
property :desc, String
|
35
36
|
|
36
37
|
# @!attribute [r] currency
|
37
38
|
# Currency used for the item's price.
|
38
39
|
# @return [String]
|
39
|
-
|
40
|
+
property :currency, String
|
40
41
|
|
41
42
|
# @!attribute [r] price
|
42
43
|
# Base price of a single unit to be sold.
|
43
44
|
# @return [GOBL::Num::Amount]
|
44
|
-
|
45
|
+
property :price, GOBL::Num::Amount
|
46
|
+
validates :price, presence: true
|
45
47
|
|
46
48
|
# @!attribute [r] unit
|
47
49
|
# Unit of measure.
|
48
50
|
# @return [GOBL::Org::Unit]
|
49
|
-
|
51
|
+
property :unit, GOBL::Org::Unit
|
50
52
|
|
51
53
|
# @!attribute [r] codes
|
52
54
|
# List of additional codes, IDs, or SKUs which can be used to identify the item. The should be agreed upon between supplier and customer.
|
53
55
|
# @return [Array<ItemCode>]
|
54
|
-
|
56
|
+
property :codes, [ItemCode]
|
55
57
|
|
56
58
|
# @!attribute [r] origin
|
57
59
|
# Country code of where this item was from originally.
|
58
60
|
# @return [GOBL::L10n::CountryCode]
|
59
|
-
|
61
|
+
property :origin, GOBL::L10n::CountryCode
|
60
62
|
|
61
63
|
# @!attribute [r] meta
|
62
64
|
# Additional meta information that may be useful
|
63
65
|
# @return [GOBL::Org::Meta]
|
64
|
-
|
65
|
-
|
66
|
-
# Creates a new object from a hash of GOBL data
|
67
|
-
#
|
68
|
-
# @param data [Hash] a hash of GOBL data
|
69
|
-
#
|
70
|
-
# @return [Item] the object created from the given data
|
71
|
-
def self.from_gobl!(data)
|
72
|
-
data = GOBL::Types::Hash[data]
|
73
|
-
|
74
|
-
new(
|
75
|
-
uuid: data['uuid'] ? GOBL::UUID::UUID.from_gobl!(data['uuid']) : nil,
|
76
|
-
ref: data['ref'],
|
77
|
-
name: data['name'],
|
78
|
-
desc: data['desc'],
|
79
|
-
currency: data['currency'],
|
80
|
-
price: data['price'],
|
81
|
-
unit: data['unit'] ? GOBL::Org::Unit.from_gobl!(data['unit']) : nil,
|
82
|
-
codes: data['codes']&.map { |item| ItemCode.from_gobl!(item) },
|
83
|
-
origin: data['origin'] ? GOBL::L10n::CountryCode.from_gobl!(data['origin']) : nil,
|
84
|
-
meta: data['meta'] ? GOBL::Org::Meta.from_gobl!(data['meta']) : nil
|
85
|
-
)
|
86
|
-
end
|
87
|
-
|
88
|
-
# Returns a hash of GOBL data representing the current object
|
89
|
-
#
|
90
|
-
# @return [Hash] the array of GOBL data that represents the current object
|
91
|
-
def to_gobl
|
92
|
-
{
|
93
|
-
'uuid' => attributes[:uuid]&.to_gobl,
|
94
|
-
'ref' => attributes[:ref],
|
95
|
-
'name' => attributes[:name],
|
96
|
-
'desc' => attributes[:desc],
|
97
|
-
'currency' => attributes[:currency],
|
98
|
-
'price' => attributes[:price]&.to_gobl,
|
99
|
-
'unit' => attributes[:unit]&.to_gobl,
|
100
|
-
'codes' => attributes[:codes]&.map { |item| item&.to_gobl },
|
101
|
-
'origin' => attributes[:origin]&.to_gobl,
|
102
|
-
'meta' => attributes[:meta]&.to_gobl
|
103
|
-
}.compact
|
104
|
-
end
|
105
|
-
|
106
|
-
# @!method self.new(attrs)
|
107
|
-
#
|
108
|
-
# Returns a {Item} object from a given hash of attributes. Nested
|
109
|
-
# attributes are supported: the constructor will instantiate the proper GOBL
|
110
|
-
# objects when nested hashes or arrays are given as part of the `attrs`
|
111
|
-
# parameter.
|
112
|
-
#
|
113
|
-
# The `new` method will only allow to create a new object if all attributes
|
114
|
-
# marked as mandatory and not calculated in the JSON schema are provided.
|
115
|
-
#
|
116
|
-
# @param attrs [Hash] the hash of attributes
|
117
|
-
#
|
118
|
-
# @return [Item] the object corresponding to the given input
|
66
|
+
property :meta, GOBL::Org::Meta
|
119
67
|
end
|
120
68
|
end
|
121
69
|
end
|