gobl 0.1.2 → 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.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ext/hashme.rb +28 -0
  3. data/lib/gobl/bill/advances.rb +1 -77
  4. data/lib/gobl/bill/charge.rb +11 -65
  5. data/lib/gobl/bill/delivery.rb +5 -47
  6. data/lib/gobl/bill/discount.rb +11 -65
  7. data/lib/gobl/bill/exchange_rates.rb +1 -77
  8. data/lib/gobl/bill/invoice.rb +28 -104
  9. data/lib/gobl/bill/invoice_type.rb +3 -134
  10. data/lib/gobl/bill/line.rb +13 -65
  11. data/lib/gobl/bill/line_charge.rb +5 -47
  12. data/lib/gobl/bill/line_discount.rb +5 -47
  13. data/lib/gobl/bill/ordering.rb +2 -38
  14. data/lib/gobl/bill/outlay.rb +11 -59
  15. data/lib/gobl/bill/payment.rb +5 -47
  16. data/lib/gobl/bill/preceding.rb +12 -62
  17. data/lib/gobl/bill/scheme_keys.rb +1 -77
  18. data/lib/gobl/bill/tax.rb +4 -44
  19. data/lib/gobl/bill/totals.rb +17 -71
  20. data/lib/gobl/cal/date.rb +1 -90
  21. data/lib/gobl/cal/period.rb +5 -41
  22. data/lib/gobl/currency/code.rb +3 -134
  23. data/lib/gobl/currency/exchange_rate.rb +5 -41
  24. data/lib/gobl/document.rb +1 -58
  25. data/lib/gobl/dsig/digest.rb +5 -41
  26. data/lib/gobl/dsig/signature.rb +1 -90
  27. data/lib/gobl/enum.rb +81 -0
  28. data/lib/gobl/envelope.rb +9 -48
  29. data/lib/gobl/header.rb +10 -56
  30. data/lib/gobl/i18n/string.rb +1 -58
  31. data/lib/gobl/l10n/code.rb +1 -90
  32. data/lib/gobl/l10n/country_code.rb +3 -134
  33. data/lib/gobl/map.rb +62 -0
  34. data/lib/gobl/note/message.rb +5 -44
  35. data/lib/gobl/num/amount.rb +6 -35
  36. data/lib/gobl/object.rb +21 -0
  37. data/lib/gobl/operations.rb +3 -3
  38. data/lib/gobl/org/address.rb +18 -80
  39. data/lib/gobl/org/code.rb +1 -90
  40. data/lib/gobl/org/coordinates.rb +5 -47
  41. data/lib/gobl/org/email.rb +6 -47
  42. data/lib/gobl/org/inbox.rb +8 -50
  43. data/lib/gobl/org/item.rb +13 -65
  44. data/lib/gobl/org/item_code.rb +4 -41
  45. data/lib/gobl/org/key.rb +1 -90
  46. data/lib/gobl/org/meta.rb +1 -58
  47. data/lib/gobl/org/name.rb +12 -62
  48. data/lib/gobl/org/note.rb +6 -47
  49. data/lib/gobl/org/note_key.rb +3 -134
  50. data/lib/gobl/org/party.rb +14 -71
  51. data/lib/gobl/org/person.rb +9 -56
  52. data/lib/gobl/org/registration.rb +9 -59
  53. data/lib/gobl/org/source_key.rb +3 -134
  54. data/lib/gobl/org/tax_identity.rb +8 -53
  55. data/lib/gobl/org/telephone.rb +5 -44
  56. data/lib/gobl/org/unit.rb +1 -136
  57. data/lib/gobl/pay/advance.rb +11 -59
  58. data/lib/gobl/pay/card.rb +5 -41
  59. data/lib/gobl/pay/credit_transfer.rb +6 -50
  60. data/lib/gobl/pay/direct_debit.rb +4 -44
  61. data/lib/gobl/pay/due_date.rb +8 -50
  62. data/lib/gobl/pay/instructions.rb +11 -62
  63. data/lib/gobl/pay/method_key.rb +3 -134
  64. data/lib/gobl/pay/online.rb +4 -41
  65. data/lib/gobl/pay/term_key.rb +3 -134
  66. data/lib/gobl/pay/terms.rb +6 -47
  67. data/lib/gobl/stamp.rb +5 -41
  68. data/lib/gobl/struct.rb +15 -15
  69. data/lib/gobl/tax/category.rb +9 -50
  70. data/lib/gobl/tax/category_total.rb +11 -53
  71. data/lib/gobl/tax/combo.rb +6 -47
  72. data/lib/gobl/tax/localities.rb +1 -77
  73. data/lib/gobl/tax/locality.rb +6 -44
  74. data/lib/gobl/tax/rate.rb +8 -47
  75. data/lib/gobl/tax/rate_total.rb +9 -50
  76. data/lib/gobl/tax/rate_total_surcharge.rb +5 -41
  77. data/lib/gobl/tax/rate_value.rb +6 -47
  78. data/lib/gobl/tax/region.rb +12 -56
  79. data/lib/gobl/tax/scheme.rb +8 -50
  80. data/lib/gobl/tax/schemes.rb +1 -77
  81. data/lib/gobl/tax/set.rb +1 -77
  82. data/lib/gobl/tax/total.rb +4 -41
  83. data/lib/gobl/uuid/uuid.rb +1 -90
  84. data/lib/gobl/value.rb +58 -0
  85. data/lib/gobl/version.rb +1 -1
  86. data/lib/gobl.rb +3 -1
  87. data/lib/gobl_extensions/document_helper.rb +3 -3
  88. data/lib/gobl_extensions/envelope_helper.rb +5 -0
  89. data/lib/gobl_extensions/i18n/value_keys_helper.rb +3 -3
  90. data/lib/gobl_extensions/tax/region_helper.rb +3 -9
  91. metadata +11 -36
  92. data/home/cavalle/workspace/invopop/gobl.ruby/gobl.gemspec +0 -30
  93. data/lib/gobl/types.rb +0 -17
@@ -9,127 +9,70 @@
9
9
  module GOBL
10
10
  module Org
11
11
  # Party represents a person or business entity.
12
- class Party < GOBL::Struct
12
+ class Party < GOBL::Object
13
13
  # The Schema ID of the GOBL Party structure
14
14
  SCHEMA_ID = 'https://gobl.org/draft-0/org/party'
15
15
 
16
16
  # @!attribute [r] id
17
17
  # Internal ID used to identify the party inside a document.
18
18
  # @return [String]
19
- attribute? :id, GOBL::Types::String.optional
19
+ property :id, String
20
20
 
21
21
  # @!attribute [r] uuid
22
22
  # Unique identity code
23
23
  # @return [GOBL::UUID::UUID]
24
- attribute? :uuid, GOBL::UUID::UUID.optional
24
+ property :uuid, GOBL::UUID::UUID
25
25
 
26
26
  # @!attribute [r] tax_id
27
27
  # The entity's legal ID code used for tax purposes. They may have other numbers, but we're only interested in those valid for tax purposes.
28
28
  # @return [GOBL::Org::TaxIdentity]
29
- attribute? :tax_id, GOBL::Org::TaxIdentity.optional
29
+ property :tax_id, GOBL::Org::TaxIdentity
30
30
 
31
31
  # @!attribute [r] name
32
32
  # Legal name or representation of the organization.
33
33
  # @return [String]
34
- attribute :name, GOBL::Types::String
34
+ property :name, String
35
+ validates :name, presence: true
35
36
 
36
37
  # @!attribute [r] alias
37
38
  # Alternate short name.
38
39
  # @return [String]
39
- attribute? :alias, GOBL::Types::String.optional
40
+ property :alias, String
40
41
 
41
42
  # @!attribute [r] people
42
43
  # Details of physical people who represent the party.
43
44
  # @return [Array<GOBL::Org::Person>]
44
- attribute? :people, GOBL::Types::Array.of(GOBL::Org::Person).optional
45
+ property :people, [GOBL::Org::Person]
45
46
 
46
47
  # @!attribute [r] inboxes
47
48
  # Digital inboxes used for forwarding electronic versions of documents
48
49
  # @return [Array<GOBL::Org::Inbox>]
49
- attribute? :inboxes, GOBL::Types::Array.of(GOBL::Org::Inbox).optional
50
+ property :inboxes, [GOBL::Org::Inbox]
50
51
 
51
52
  # @!attribute [r] addresses
52
53
  # Regular post addresses for where information should be sent if needed.
53
54
  # @return [Array<GOBL::Org::Address>]
54
- attribute? :addresses, GOBL::Types::Array.of(GOBL::Org::Address).optional
55
+ property :addresses, [GOBL::Org::Address]
55
56
 
56
57
  # @!attribute [r] emails
57
58
  # Electronic mail addresses
58
59
  # @return [Array<GOBL::Org::Email>]
59
- attribute? :emails, GOBL::Types::Array.of(GOBL::Org::Email).optional
60
+ property :emails, [GOBL::Org::Email]
60
61
 
61
62
  # @!attribute [r] telephones
62
63
  # Regular telephone numbers
63
64
  # @return [Array<GOBL::Org::Telephone>]
64
- attribute? :telephones, GOBL::Types::Array.of(GOBL::Org::Telephone).optional
65
+ property :telephones, [GOBL::Org::Telephone]
65
66
 
66
67
  # @!attribute [r] registration
67
68
  # Additional registration details about the company that may need to be included in a document.
68
69
  # @return [GOBL::Org::Registration]
69
- attribute? :registration, GOBL::Org::Registration.optional
70
+ property :registration, GOBL::Org::Registration
70
71
 
71
72
  # @!attribute [r] meta
72
73
  # Any additional semi-structured information that does not fit into the rest of the party.
73
74
  # @return [GOBL::Org::Meta]
74
- attribute? :meta, GOBL::Org::Meta.optional
75
-
76
- # Creates a new object from a hash of GOBL data
77
- #
78
- # @param data [Hash] a hash of GOBL data
79
- #
80
- # @return [Party] the object created from the given data
81
- def self.from_gobl!(data)
82
- data = GOBL::Types::Hash[data]
83
-
84
- new(
85
- id: data['id'],
86
- uuid: data['uuid'] ? GOBL::UUID::UUID.from_gobl!(data['uuid']) : nil,
87
- tax_id: data['tax_id'] ? GOBL::Org::TaxIdentity.from_gobl!(data['tax_id']) : nil,
88
- name: data['name'],
89
- alias: data['alias'],
90
- people: data['people']&.map { |item| GOBL::Org::Person.from_gobl!(item) },
91
- inboxes: data['inboxes']&.map { |item| GOBL::Org::Inbox.from_gobl!(item) },
92
- addresses: data['addresses']&.map { |item| GOBL::Org::Address.from_gobl!(item) },
93
- emails: data['emails']&.map { |item| GOBL::Org::Email.from_gobl!(item) },
94
- telephones: data['telephones']&.map { |item| GOBL::Org::Telephone.from_gobl!(item) },
95
- registration: data['registration'] ? GOBL::Org::Registration.from_gobl!(data['registration']) : nil,
96
- meta: data['meta'] ? GOBL::Org::Meta.from_gobl!(data['meta']) : nil
97
- )
98
- end
99
-
100
- # Returns a hash of GOBL data representing the current object
101
- #
102
- # @return [Hash] the array of GOBL data that represents the current object
103
- def to_gobl
104
- {
105
- 'id' => attributes[:id],
106
- 'uuid' => attributes[:uuid]&.to_gobl,
107
- 'tax_id' => attributes[:tax_id]&.to_gobl,
108
- 'name' => attributes[:name],
109
- 'alias' => attributes[:alias],
110
- 'people' => attributes[:people]&.map { |item| item&.to_gobl },
111
- 'inboxes' => attributes[:inboxes]&.map { |item| item&.to_gobl },
112
- 'addresses' => attributes[:addresses]&.map { |item| item&.to_gobl },
113
- 'emails' => attributes[:emails]&.map { |item| item&.to_gobl },
114
- 'telephones' => attributes[:telephones]&.map { |item| item&.to_gobl },
115
- 'registration' => attributes[:registration]&.to_gobl,
116
- 'meta' => attributes[:meta]&.to_gobl
117
- }.compact
118
- end
119
-
120
- # @!method self.new(attrs)
121
- #
122
- # Returns a {Party} object from a given hash of attributes. Nested
123
- # attributes are supported: the constructor will instantiate the proper GOBL
124
- # objects when nested hashes or arrays are given as part of the `attrs`
125
- # parameter.
126
- #
127
- # The `new` method will only allow to create a new object if all attributes
128
- # marked as mandatory and not calculated in the JSON schema are provided.
129
- #
130
- # @param attrs [Hash] the hash of attributes
131
- #
132
- # @return [Party] the object corresponding to the given input
75
+ property :meta, GOBL::Org::Meta
133
76
  end
134
77
  end
135
78
  end
@@ -9,92 +9,45 @@
9
9
  module GOBL
10
10
  module Org
11
11
  # Person represents a human, and how to contact them electronically.
12
- class Person < GOBL::Struct
12
+ class Person < GOBL::Object
13
13
  # The Schema ID of the GOBL Person structure
14
14
  SCHEMA_ID = 'https://gobl.org/draft-0/org/person'
15
15
 
16
16
  # @!attribute [r] id
17
17
  # Internal ID used to identify the person inside a document.
18
18
  # @return [String]
19
- attribute? :id, GOBL::Types::String.optional
19
+ property :id, String
20
20
 
21
21
  # @!attribute [r] uuid
22
22
  # Unique identity code
23
23
  # @return [GOBL::UUID::UUID]
24
- attribute? :uuid, GOBL::UUID::UUID.optional
24
+ property :uuid, GOBL::UUID::UUID
25
25
 
26
26
  # @!attribute [r] name
27
27
  # Complete details on the name of the person
28
28
  # @return [GOBL::Org::Name]
29
- attribute :name, GOBL::Org::Name
29
+ property :name, GOBL::Org::Name
30
+ validates :name, presence: true
30
31
 
31
32
  # @!attribute [r] role
32
33
  # What they do within an organization
33
34
  # @return [String]
34
- attribute? :role, GOBL::Types::String.optional
35
+ property :role, String
35
36
 
36
37
  # @!attribute [r] emails
37
38
  # Electronic mail addresses that belong to the person.
38
39
  # @return [Array<GOBL::Org::Email>]
39
- attribute? :emails, GOBL::Types::Array.of(GOBL::Org::Email).optional
40
+ property :emails, [GOBL::Org::Email]
40
41
 
41
42
  # @!attribute [r] telephones
42
43
  # Regular phone or mobile numbers
43
44
  # @return [Array<GOBL::Org::Telephone>]
44
- attribute? :telephones, GOBL::Types::Array.of(GOBL::Org::Telephone).optional
45
+ property :telephones, [GOBL::Org::Telephone]
45
46
 
46
47
  # @!attribute [r] meta
47
48
  # Data about the data.
48
49
  # @return [GOBL::Org::Meta]
49
- attribute? :meta, GOBL::Org::Meta.optional
50
-
51
- # Creates a new object from a hash of GOBL data
52
- #
53
- # @param data [Hash] a hash of GOBL data
54
- #
55
- # @return [Person] the object created from the given data
56
- def self.from_gobl!(data)
57
- data = GOBL::Types::Hash[data]
58
-
59
- new(
60
- id: data['id'],
61
- uuid: data['uuid'] ? GOBL::UUID::UUID.from_gobl!(data['uuid']) : nil,
62
- name: GOBL::Org::Name.from_gobl!(data['name']),
63
- role: data['role'],
64
- emails: data['emails']&.map { |item| GOBL::Org::Email.from_gobl!(item) },
65
- telephones: data['telephones']&.map { |item| GOBL::Org::Telephone.from_gobl!(item) },
66
- meta: data['meta'] ? GOBL::Org::Meta.from_gobl!(data['meta']) : nil
67
- )
68
- end
69
-
70
- # Returns a hash of GOBL data representing the current object
71
- #
72
- # @return [Hash] the array of GOBL data that represents the current object
73
- def to_gobl
74
- {
75
- 'id' => attributes[:id],
76
- 'uuid' => attributes[:uuid]&.to_gobl,
77
- 'name' => attributes[:name]&.to_gobl,
78
- 'role' => attributes[:role],
79
- 'emails' => attributes[:emails]&.map { |item| item&.to_gobl },
80
- 'telephones' => attributes[:telephones]&.map { |item| item&.to_gobl },
81
- 'meta' => attributes[:meta]&.to_gobl
82
- }.compact
83
- end
84
-
85
- # @!method self.new(attrs)
86
- #
87
- # Returns a {Person} object from a given hash of attributes. Nested
88
- # attributes are supported: the constructor will instantiate the proper GOBL
89
- # objects when nested hashes or arrays are given as part of the `attrs`
90
- # parameter.
91
- #
92
- # The `new` method will only allow to create a new object if all attributes
93
- # marked as mandatory and not calculated in the JSON schema are provided.
94
- #
95
- # @param attrs [Hash] the hash of attributes
96
- #
97
- # @return [Person] the object corresponding to the given input
50
+ property :meta, GOBL::Org::Meta
98
51
  end
99
52
  end
100
53
  end
@@ -9,91 +9,41 @@
9
9
  module GOBL
10
10
  module Org
11
11
  # Registration is used in countries that require additional information to be associated with a company usually related to a specific registration office.
12
- class Registration < GOBL::Struct
12
+ class Registration < GOBL::Object
13
13
  # The Schema ID of the GOBL Registration structure
14
14
  SCHEMA_ID = 'https://gobl.org/draft-0/org/registration'
15
15
 
16
16
  # @!attribute [r] uuid
17
17
  # @return [GOBL::UUID::UUID]
18
- attribute? :uuid, GOBL::UUID::UUID.optional
18
+ property :uuid, GOBL::UUID::UUID
19
19
 
20
20
  # @!attribute [r] office
21
21
  # @return [String]
22
- attribute? :office, GOBL::Types::String.optional
22
+ property :office, String
23
23
 
24
24
  # @!attribute [r] book
25
25
  # @return [String]
26
- attribute? :book, GOBL::Types::String.optional
26
+ property :book, String
27
27
 
28
28
  # @!attribute [r] volume
29
29
  # @return [String]
30
- attribute? :volume, GOBL::Types::String.optional
30
+ property :volume, String
31
31
 
32
32
  # @!attribute [r] sheet
33
33
  # @return [String]
34
- attribute? :sheet, GOBL::Types::String.optional
34
+ property :sheet, String
35
35
 
36
36
  # @!attribute [r] section
37
37
  # @return [String]
38
- attribute? :section, GOBL::Types::String.optional
38
+ property :section, String
39
39
 
40
40
  # @!attribute [r] page
41
41
  # @return [String]
42
- attribute? :page, GOBL::Types::String.optional
42
+ property :page, String
43
43
 
44
44
  # @!attribute [r] entry
45
45
  # @return [String]
46
- attribute? :entry, GOBL::Types::String.optional
47
-
48
- # Creates a new object from a hash of GOBL data
49
- #
50
- # @param data [Hash] a hash of GOBL data
51
- #
52
- # @return [Registration] the object created from the given data
53
- def self.from_gobl!(data)
54
- data = GOBL::Types::Hash[data]
55
-
56
- new(
57
- uuid: data['uuid'] ? GOBL::UUID::UUID.from_gobl!(data['uuid']) : nil,
58
- office: data['office'],
59
- book: data['book'],
60
- volume: data['volume'],
61
- sheet: data['sheet'],
62
- section: data['section'],
63
- page: data['page'],
64
- entry: data['entry']
65
- )
66
- end
67
-
68
- # Returns a hash of GOBL data representing the current object
69
- #
70
- # @return [Hash] the array of GOBL data that represents the current object
71
- def to_gobl
72
- {
73
- 'uuid' => attributes[:uuid]&.to_gobl,
74
- 'office' => attributes[:office],
75
- 'book' => attributes[:book],
76
- 'volume' => attributes[:volume],
77
- 'sheet' => attributes[:sheet],
78
- 'section' => attributes[:section],
79
- 'page' => attributes[:page],
80
- 'entry' => attributes[:entry]
81
- }.compact
82
- end
83
-
84
- # @!method self.new(attrs)
85
- #
86
- # Returns a {Registration} object from a given hash of attributes. Nested
87
- # attributes are supported: the constructor will instantiate the proper GOBL
88
- # objects when nested hashes or arrays are given as part of the `attrs`
89
- # parameter.
90
- #
91
- # The `new` method will only allow to create a new object if all attributes
92
- # marked as mandatory and not calculated in the JSON schema are provided.
93
- #
94
- # @param attrs [Hash] the hash of attributes
95
- #
96
- # @return [Registration] the object corresponding to the given input
46
+ property :entry, String
97
47
  end
98
48
  end
99
49
  end
@@ -9,7 +9,7 @@
9
9
  module GOBL
10
10
  module Org
11
11
  # SourceKey identifies the source of a tax identity
12
- class SourceKey < GOBL::Struct
12
+ class SourceKey < GOBL::Enum
13
13
  # The Schema ID of the GOBL SourceKey structure
14
14
  SCHEMA_ID = 'https://gobl.org/draft-0/org/tax-identity#/$defs/SourceKey'
15
15
 
@@ -22,139 +22,8 @@ module GOBL
22
22
  'other' => 'An other type of source not listed'
23
23
  }.freeze
24
24
 
25
- attribute :_value, GOBL::Types::String.enum(*ENUM.keys)
26
- private :_value
27
-
28
- # Creates a new object from a GOBL value
29
- #
30
- # @param data [String] the GOBL value
31
- #
32
- # @return [SourceKey] the object created from the given data
33
- def self.from_gobl!(data)
34
- new(_value: data)
35
- end
36
-
37
- # Returns a GOBL value representing the current object
38
- #
39
- # @return [String] the GOBL value that represents the current object
40
- def to_gobl
41
- _value
42
- end
43
-
44
- # Returns a {SourceKey} that corresponds to a given object. The object can be a
45
- # `Symbol`, a `String` or anything coercible into one (via `#to_s`).
46
- #
47
- # @param object [Symbol, String, #to_s] the value of the object.
48
- #
49
- # @return [SourceKey] the object corresponding to the given value.
50
- #
51
- # @example Instantiating from a symbol
52
- # source_key = GOBL::Org::SourceKey.new(:tax_agency)
53
- #
54
- # @example Instantiating from a string
55
- # source_key = GOBL::Org::SourceKey.new('tax-agency')
56
- def self.new(object)
57
- case object
58
- when Hash, self # internal use, not to be used in public calls
59
- super
60
- when Symbol
61
- new find_by_sym(object)
62
- else
63
- super _value: object.to_s
64
- end
65
- end
66
-
67
- # Returns the string representation of the current object
68
- #
69
- # @return [String] the string representation of the current object
70
- def to_s
71
- _value.to_s
72
- end
73
-
74
- # Returns the symbol representation of the current object
75
- #
76
- # @return [Symbol] the symbol representation of the current object
77
- def to_sym
78
- to_s.parameterize.underscore.to_sym
79
- end
80
-
81
- # Returns whether the current object is equivalent to a given one. In addition
82
- # to {SourceKey} objects, the current object can be compared to a `Symbol`, a
83
- # `String` or anything coercible into one (via `#to_s`)
84
- #
85
- # @param other [SourceKey, Symbol, String, #to_s] the other object to compare to
86
- #
87
- # @return [Boolean] `true` if the objects are equivalent, `false` otherwise
88
- #
89
- # @example Comparing to another {SourceKey} object
90
- # source_key = GOBL::Org::SourceKey.new('tax-agency')
91
- # source_key == GOBL::Org::SourceKey.new('tax-agency') #=> true
92
- # source_key == GOBL::Org::SourceKey.new('passport') #=> false
93
- #
94
- # @example Comparing to a string
95
- # source_key = GOBL::Org::SourceKey.new('tax-agency')
96
- # source_key == 'tax-agency' #=> true
97
- # source_key == 'passport' #=> false
98
- #
99
- # @example Comparing to a symbol
100
- # source_key = GOBL::Org::SourceKey.new('tax-agency')
101
- # source_key == :tax_agency #=> true
102
- # source_key == :passport #=> false
103
- def ==(other)
104
- case other
105
- when self.class
106
- super
107
- when Symbol
108
- to_sym == other
109
- else
110
- to_s == other.to_s
111
- end
112
- end
113
-
114
- # Returns an array with all the enumerated objects of this type
115
- #
116
- # @return [Array<SourceKey>] the array of enumerated objects
117
- def self.all
118
- ENUM.keys.map { |key| new(key) }
119
- end
120
-
121
- # @api private
122
- def self.find_by_sym(sym)
123
- all.find { |object| object.to_sym == sym }
124
- end
125
-
126
- # @api private
127
- def self.find_by_inquirer(method_name)
128
- method_name =~ /(.+)\?$/ && find_by_sym(Regexp.last_match(1).to_sym)
129
- end
130
-
131
- # Returns the description of the current object
132
- #
133
- # @return [String] the description of the current object
134
- def description
135
- ENUM.fetch(_value, _value)
136
- end
137
-
138
- # @api private
139
- def respond_to_missing?(method_name, include_private = false)
140
- self.class.find_by_inquirer(method_name) || super
141
- end
142
-
143
- # Enables dynamic value inquirers like `SourceKey#tax_agency?` for
144
- # each of the declared enum values (see {ENUM}). Each inquirer returns a
145
- # `Boolean` denoting whether the value equals the enquired value (`true`) or
146
- # not (`false`)
147
- #
148
- # @example
149
- # source_key = GOBL::Org::SourceKey.new('tax-agency')
150
- # source_key.tax_agency? # => true
151
- # source_key.passport? # => false
152
- def method_missing(method_name, *args, &block)
153
- if value = self.class.find_by_inquirer(method_name)
154
- self == value
155
- else
156
- super
157
- end
25
+ def strict_enum?
26
+ true
158
27
  end
159
28
  end
160
29
  end
@@ -9,85 +9,40 @@
9
9
  module GOBL
10
10
  module Org
11
11
  # TaxIdentity stores the details required to identify an entity for tax purposes.
12
- class TaxIdentity < GOBL::Struct
12
+ class TaxIdentity < GOBL::Object
13
13
  # The Schema ID of the GOBL TaxIdentity structure
14
14
  SCHEMA_ID = 'https://gobl.org/draft-0/org/tax-identity'
15
15
 
16
16
  # @!attribute [r] uuid
17
17
  # Unique universal identity code.
18
18
  # @return [GOBL::UUID::UUID]
19
- attribute? :uuid, GOBL::UUID::UUID.optional
19
+ property :uuid, GOBL::UUID::UUID
20
20
 
21
21
  # @!attribute [r] country
22
22
  # ISO country code for Where the tax identity was issued.
23
23
  # @return [GOBL::L10n::CountryCode]
24
- attribute :country, GOBL::L10n::CountryCode
24
+ property :country, GOBL::L10n::CountryCode
25
+ validates :country, presence: true
25
26
 
26
27
  # @!attribute [r] locality
27
28
  # Where inside a country the Tax ID was issued, if required.
28
29
  # @return [GOBL::L10n::Code]
29
- attribute? :locality, GOBL::L10n::Code.optional
30
+ property :locality, GOBL::L10n::Code
30
31
 
31
32
  # @!attribute [r] source
32
33
  # What is the source document of this tax identity.
33
34
  # @return [SourceKey]
34
- attribute? :source, SourceKey.optional
35
+ property :source, SourceKey
35
36
 
36
37
  # @!attribute [r] code
37
38
  # Tax identity Code
38
39
  # @return [String]
39
- attribute? :code, GOBL::Types::String.optional
40
+ property :code, String
40
41
 
41
42
  # @!attribute [r] meta
42
43
  # Additional details that may be required.
43
44
  # @return [GOBL::Org::Meta]
44
- attribute? :meta, GOBL::Org::Meta.optional
45
-
46
- # Creates a new object from a hash of GOBL data
47
- #
48
- # @param data [Hash] a hash of GOBL data
49
- #
50
- # @return [TaxIdentity] the object created from the given data
51
- def self.from_gobl!(data)
52
- data = GOBL::Types::Hash[data]
53
-
54
- new(
55
- uuid: data['uuid'] ? GOBL::UUID::UUID.from_gobl!(data['uuid']) : nil,
56
- country: GOBL::L10n::CountryCode.from_gobl!(data['country']),
57
- locality: data['locality'] ? GOBL::L10n::Code.from_gobl!(data['locality']) : nil,
58
- source: data['source'] ? SourceKey.from_gobl!(data['source']) : nil,
59
- code: data['code'],
60
- meta: data['meta'] ? GOBL::Org::Meta.from_gobl!(data['meta']) : nil
61
- )
62
- end
63
-
64
- # Returns a hash of GOBL data representing the current object
65
- #
66
- # @return [Hash] the array of GOBL data that represents the current object
67
- def to_gobl
68
- {
69
- 'uuid' => attributes[:uuid]&.to_gobl,
70
- 'country' => attributes[:country]&.to_gobl,
71
- 'locality' => attributes[:locality]&.to_gobl,
72
- 'source' => attributes[:source]&.to_gobl,
73
- 'code' => attributes[:code],
74
- 'meta' => attributes[:meta]&.to_gobl
75
- }.compact
76
- end
77
-
78
- # @!method self.new(attrs)
79
- #
80
- # Returns a {TaxIdentity} object from a given hash of attributes. Nested
81
- # attributes are supported: the constructor will instantiate the proper GOBL
82
- # objects when nested hashes or arrays are given as part of the `attrs`
83
- # parameter.
84
- #
85
- # The `new` method will only allow to create a new object if all attributes
86
- # marked as mandatory and not calculated in the JSON schema are provided.
87
- #
88
- # @param attrs [Hash] the hash of attributes
89
- #
90
- # @return [TaxIdentity] the object corresponding to the given input
45
+ property :meta, GOBL::Org::Meta
91
46
  end
92
47
  end
93
48
  end
@@ -9,64 +9,25 @@
9
9
  module GOBL
10
10
  module Org
11
11
  # Telephone describes what is expected for a telephone number.
12
- class Telephone < GOBL::Struct
12
+ class Telephone < GOBL::Object
13
13
  # The Schema ID of the GOBL Telephone structure
14
14
  SCHEMA_ID = 'https://gobl.org/draft-0/org/telephone'
15
15
 
16
16
  # @!attribute [r] uuid
17
17
  # Unique identity code
18
18
  # @return [GOBL::UUID::UUID]
19
- attribute? :uuid, GOBL::UUID::UUID.optional
19
+ property :uuid, GOBL::UUID::UUID
20
20
 
21
21
  # @!attribute [r] label
22
22
  # Identifier for this number.
23
23
  # @return [String]
24
- attribute? :label, GOBL::Types::String.optional
24
+ property :label, String
25
25
 
26
26
  # @!attribute [r] num
27
27
  # The number to be dialed in ITU E.164 international format.
28
28
  # @return [String]
29
- attribute :num, GOBL::Types::String
30
-
31
- # Creates a new object from a hash of GOBL data
32
- #
33
- # @param data [Hash] a hash of GOBL data
34
- #
35
- # @return [Telephone] the object created from the given data
36
- def self.from_gobl!(data)
37
- data = GOBL::Types::Hash[data]
38
-
39
- new(
40
- uuid: data['uuid'] ? GOBL::UUID::UUID.from_gobl!(data['uuid']) : nil,
41
- label: data['label'],
42
- num: data['num']
43
- )
44
- end
45
-
46
- # Returns a hash of GOBL data representing the current object
47
- #
48
- # @return [Hash] the array of GOBL data that represents the current object
49
- def to_gobl
50
- {
51
- 'uuid' => attributes[:uuid]&.to_gobl,
52
- 'label' => attributes[:label],
53
- 'num' => attributes[:num]
54
- }.compact
55
- end
56
-
57
- # @!method self.new(attrs)
58
- #
59
- # Returns a {Telephone} object from a given hash of attributes. Nested
60
- # attributes are supported: the constructor will instantiate the proper GOBL
61
- # objects when nested hashes or arrays are given as part of the `attrs`
62
- # parameter.
63
- #
64
- # The `new` method will only allow to create a new object if all attributes
65
- # marked as mandatory and not calculated in the JSON schema are provided.
66
- #
67
- # @param attrs [Hash] the hash of attributes
68
- #
69
- # @return [Telephone] the object corresponding to the given input
29
+ property :num, String
30
+ validates :num, presence: true
70
31
  end
71
32
  end
72
33
  end