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,57 +9,20 @@
9
9
  module GOBL
10
10
  module Org
11
11
  # ItemCode contains a value and optional label property that means additional codes can be added to an item.
12
- class ItemCode < GOBL::Struct
12
+ class ItemCode < GOBL::Object
13
13
  # The Schema ID of the GOBL ItemCode structure
14
14
  SCHEMA_ID = 'https://gobl.org/draft-0/org/item#/$defs/ItemCode'
15
15
 
16
16
  # @!attribute [r] label
17
17
  # Local or human reference for the type of code the value represents.
18
18
  # @return [String]
19
- attribute? :label, GOBL::Types::String.optional
19
+ property :label, String
20
20
 
21
21
  # @!attribute [r] value
22
22
  # The item code's value.
23
23
  # @return [String]
24
- attribute :value, GOBL::Types::String
25
-
26
- # Creates a new object from a hash of GOBL data
27
- #
28
- # @param data [Hash] a hash of GOBL data
29
- #
30
- # @return [ItemCode] the object created from the given data
31
- def self.from_gobl!(data)
32
- data = GOBL::Types::Hash[data]
33
-
34
- new(
35
- label: data['label'],
36
- value: data['value']
37
- )
38
- end
39
-
40
- # Returns a hash of GOBL data representing the current object
41
- #
42
- # @return [Hash] the array of GOBL data that represents the current object
43
- def to_gobl
44
- {
45
- 'label' => attributes[:label],
46
- 'value' => attributes[:value]
47
- }.compact
48
- end
49
-
50
- # @!method self.new(attrs)
51
- #
52
- # Returns a {ItemCode} object from a given hash of attributes. Nested
53
- # attributes are supported: the constructor will instantiate the proper GOBL
54
- # objects when nested hashes or arrays are given as part of the `attrs`
55
- # parameter.
56
- #
57
- # The `new` method will only allow to create a new object if all attributes
58
- # marked as mandatory and not calculated in the JSON schema are provided.
59
- #
60
- # @param attrs [Hash] the hash of attributes
61
- #
62
- # @return [ItemCode] the object corresponding to the given input
24
+ property :value, String
25
+ validates :value, presence: true
63
26
  end
64
27
  end
65
28
  end
data/lib/gobl/org/key.rb CHANGED
@@ -9,98 +9,9 @@
9
9
  module GOBL
10
10
  module Org
11
11
  # Text identifier to be used instead of a code for a more verbose but readable identifier.
12
- class Key < GOBL::Struct
12
+ class Key < GOBL::Value
13
13
  # The Schema ID of the GOBL Key structure
14
14
  SCHEMA_ID = 'https://gobl.org/draft-0/org/key'
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 [Key] 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 {Key} 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 [Key] the object corresponding to the given value.
41
- #
42
- # @example Instantiating from a symbol
43
- # key = GOBL::Org::Key.new(:value)
44
- #
45
- # @example Instantiating from a string
46
- # key = GOBL::Org::Key.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 {Key} 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 [Key, 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 {Key} object
81
- # key = GOBL::Org::Key.new('value')
82
- # key == GOBL::Org::Key.new('value') #=> true
83
- # key == GOBL::Org::Key.new('other') #=> false
84
- #
85
- # @example Comparing to a string
86
- # key = GOBL::Org::Key.new('value')
87
- # key == 'value' #=> true
88
- # key == 'other' #=> false
89
- #
90
- # @example Comparing to a symbol
91
- # key = GOBL::Org::Key.new('value')
92
- # key == :value #=> true
93
- # key == :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/meta.rb CHANGED
@@ -9,64 +9,7 @@
9
9
  module GOBL
10
10
  module Org
11
11
  # Meta defines a structure for data about the data being defined.
12
- class Meta < GOBL::Struct
13
- extend Forwardable
14
- include Enumerable
15
-
16
- # The Schema ID of the GOBL Meta structure
17
- SCHEMA_ID = 'https://gobl.org/draft-0/org/meta'
18
-
19
- attribute :_value, GOBL::Types::Hash
20
-
21
- # @!method [](key)
22
- # Returns the value associated with the given key
23
- # @param key [Object] the key
24
- # @return [Object] the value associated with the given key
25
- #
26
- # @!method each
27
- # Iterates over each key-value pair in the map
28
- # @overload each(&block)
29
- # Calls the given block with each key-value pair in the map
30
- # @yield [key, value] a key-value pair of the map
31
- # @return [self] the object itself
32
- # @overload each
33
- # Returns an Enumerator that iterates over the key-value pairs in the map
34
- # @return [Enumerator] the enumerator of the key-value pairs
35
- #
36
- # @!method empty?
37
- # Returns `true` if the number of entires in the map is zero, `false` otherwise.
38
- # @return [Boolean] whether the map is empty or not
39
- #
40
- # @!method length
41
- # Returns the number of entries in the map
42
- # @return [Integer] the number of entries in the map
43
- #
44
- # @!method each_key
45
- # Iterates over each key in the map
46
- # @overload each(&block)
47
- # Calls the given block with each key in the map
48
- # @yield [key] a key of the map
49
- # @return [self] the object itself
50
- # @overload each
51
- # Returns an Enumerator that iterates over the keys in the map
52
- # @return [Enumerator] the enumerator of the keys
53
- def_delegators :_value, :[], :each, :empty?, :length, :each_key
54
-
55
- # Creates a new object from a hash of GOBL data
56
- #
57
- # @param data [Hash] a hash of GOBL data
58
- #
59
- # @return [Meta] the object created from the given data
60
- def self.from_gobl!(data)
61
- new(_value: data)
62
- end
63
-
64
- # Returns a hash of GOBL data representing the current object
65
- #
66
- # @return [Hash] the hash of GOBL data that represents the current object
67
- def to_gobl
68
- _value
69
- end
12
+ class Meta < GOBL::Map
70
13
  end
71
14
  end
72
15
  end
data/lib/gobl/org/name.rb CHANGED
@@ -9,106 +9,56 @@
9
9
  module GOBL
10
10
  module Org
11
11
  # Name represents what a human is called.
12
- class Name < GOBL::Struct
12
+ class Name < GOBL::Object
13
13
  # The Schema ID of the GOBL Name structure
14
14
  SCHEMA_ID = 'https://gobl.org/draft-0/org/name'
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] alias
22
22
  # What the person would like to be called
23
23
  # @return [String]
24
- attribute? :alias, GOBL::Types::String.optional
24
+ property :alias, String
25
25
 
26
26
  # @!attribute [r] prefix
27
27
  # Additional prefix to add to name, like Mrs. or Mr.
28
28
  # @return [String]
29
- attribute? :prefix, GOBL::Types::String.optional
29
+ property :prefix, String
30
30
 
31
31
  # @!attribute [r] given
32
32
  # Person's given or first name
33
33
  # @return [String]
34
- attribute :given, GOBL::Types::String
34
+ property :given, String
35
+ validates :given, presence: true
35
36
 
36
37
  # @!attribute [r] middle
37
38
  # Middle names or initials
38
39
  # @return [String]
39
- attribute? :middle, GOBL::Types::String.optional
40
+ property :middle, String
40
41
 
41
42
  # @!attribute [r] surname
42
43
  # Second or Family name.
43
44
  # @return [String]
44
- attribute :surname, GOBL::Types::String
45
+ property :surname, String
46
+ validates :surname, presence: true
45
47
 
46
48
  # @!attribute [r] surname2
47
49
  # Additional second of family name.
48
50
  # @return [String]
49
- attribute? :surname2, GOBL::Types::String.optional
51
+ property :surname2, String
50
52
 
51
53
  # @!attribute [r] suffix
52
54
  # Titles to include after the name.
53
55
  # @return [String]
54
- attribute? :suffix, GOBL::Types::String.optional
56
+ property :suffix, String
55
57
 
56
58
  # @!attribute [r] meta
57
59
  # Any additional useful data.
58
60
  # @return [GOBL::Org::Meta]
59
- attribute? :meta, GOBL::Org::Meta.optional
60
-
61
- # Creates a new object from a hash of GOBL data
62
- #
63
- # @param data [Hash] a hash of GOBL data
64
- #
65
- # @return [Name] the object created from the given data
66
- def self.from_gobl!(data)
67
- data = GOBL::Types::Hash[data]
68
-
69
- new(
70
- uuid: data['uuid'] ? GOBL::UUID::UUID.from_gobl!(data['uuid']) : nil,
71
- alias: data['alias'],
72
- prefix: data['prefix'],
73
- given: data['given'],
74
- middle: data['middle'],
75
- surname: data['surname'],
76
- surname2: data['surname2'],
77
- suffix: data['suffix'],
78
- meta: data['meta'] ? GOBL::Org::Meta.from_gobl!(data['meta']) : nil
79
- )
80
- end
81
-
82
- # Returns a hash of GOBL data representing the current object
83
- #
84
- # @return [Hash] the array of GOBL data that represents the current object
85
- def to_gobl
86
- {
87
- 'uuid' => attributes[:uuid]&.to_gobl,
88
- 'alias' => attributes[:alias],
89
- 'prefix' => attributes[:prefix],
90
- 'given' => attributes[:given],
91
- 'middle' => attributes[:middle],
92
- 'surname' => attributes[:surname],
93
- 'surname2' => attributes[:surname2],
94
- 'suffix' => attributes[:suffix],
95
- 'meta' => attributes[:meta]&.to_gobl
96
- }.compact
97
- end
98
-
99
- # @!method self.new(attrs)
100
- #
101
- # Returns a {Name} object from a given hash of attributes. Nested
102
- # attributes are supported: the constructor will instantiate the proper GOBL
103
- # objects when nested hashes or arrays are given as part of the `attrs`
104
- # parameter.
105
- #
106
- # The `new` method will only allow to create a new object if all attributes
107
- # marked as mandatory and not calculated in the JSON schema are provided.
108
- #
109
- # @param attrs [Hash] the hash of attributes
110
- #
111
- # @return [Name] the object corresponding to the given input
61
+ property :meta, GOBL::Org::Meta
112
62
  end
113
63
  end
114
64
  end
data/lib/gobl/org/note.rb CHANGED
@@ -9,71 +9,30 @@
9
9
  module GOBL
10
10
  module Org
11
11
  # Note represents a free text of additional information that may be added to a document.
12
- class Note < GOBL::Struct
12
+ class Note < GOBL::Object
13
13
  # The Schema ID of the GOBL Note structure
14
14
  SCHEMA_ID = 'https://gobl.org/draft-0/org/note'
15
15
 
16
16
  # @!attribute [r] key
17
17
  # Key specifying subject of the text
18
18
  # @return [NoteKey]
19
- attribute? :key, NoteKey.optional
19
+ property :key, NoteKey
20
20
 
21
21
  # @!attribute [r] code
22
22
  # Code used for additional data that may be required to identify the note.
23
23
  # @return [String]
24
- attribute? :code, GOBL::Types::String.optional
24
+ property :code, String
25
25
 
26
26
  # @!attribute [r] src
27
27
  # Source of this note, especially useful when auto-generated.
28
28
  # @return [String]
29
- attribute? :src, GOBL::Types::String.optional
29
+ property :src, String
30
30
 
31
31
  # @!attribute [r] text
32
32
  # The contents of the note
33
33
  # @return [String]
34
- attribute :text, GOBL::Types::String
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 [Note] the object created from the given data
41
- def self.from_gobl!(data)
42
- data = GOBL::Types::Hash[data]
43
-
44
- new(
45
- key: data['key'] ? NoteKey.from_gobl!(data['key']) : nil,
46
- code: data['code'],
47
- src: data['src'],
48
- text: data['text']
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
- 'key' => attributes[:key]&.to_gobl,
58
- 'code' => attributes[:code],
59
- 'src' => attributes[:src],
60
- 'text' => attributes[:text]
61
- }.compact
62
- end
63
-
64
- # @!method self.new(attrs)
65
- #
66
- # Returns a {Note} 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 [Note] the object corresponding to the given input
34
+ property :text, String
35
+ validates :text, presence: true
77
36
  end
78
37
  end
79
38
  end
@@ -9,7 +9,7 @@
9
9
  module GOBL
10
10
  module Org
11
11
  # NoteKey identifies the type of note being edited
12
- class NoteKey < GOBL::Struct
12
+ class NoteKey < GOBL::Enum
13
13
  # The Schema ID of the GOBL NoteKey structure
14
14
  SCHEMA_ID = 'https://gobl.org/draft-0/org/note#/$defs/NoteKey'
15
15
 
@@ -42,139 +42,8 @@ module GOBL
42
42
  'tax' => 'Tax declaration'
43
43
  }.freeze
44
44
 
45
- attribute :_value, GOBL::Types::String.enum(*ENUM.keys)
46
- private :_value
47
-
48
- # Creates a new object from a GOBL value
49
- #
50
- # @param data [String] the GOBL value
51
- #
52
- # @return [NoteKey] the object created from the given data
53
- def self.from_gobl!(data)
54
- new(_value: data)
55
- end
56
-
57
- # Returns a GOBL value representing the current object
58
- #
59
- # @return [String] the GOBL value that represents the current object
60
- def to_gobl
61
- _value
62
- end
63
-
64
- # Returns a {NoteKey} that corresponds to a given object. The object can be a
65
- # `Symbol`, a `String` or anything coercible into one (via `#to_s`).
66
- #
67
- # @param object [Symbol, String, #to_s] the value of the object.
68
- #
69
- # @return [NoteKey] the object corresponding to the given value.
70
- #
71
- # @example Instantiating from a symbol
72
- # note_key = GOBL::Org::NoteKey.new(:goods)
73
- #
74
- # @example Instantiating from a string
75
- # note_key = GOBL::Org::NoteKey.new('goods')
76
- def self.new(object)
77
- case object
78
- when Hash, self # internal use, not to be used in public calls
79
- super
80
- when Symbol
81
- new find_by_sym(object)
82
- else
83
- super _value: object.to_s
84
- end
85
- end
86
-
87
- # Returns the string representation of the current object
88
- #
89
- # @return [String] the string representation of the current object
90
- def to_s
91
- _value.to_s
92
- end
93
-
94
- # Returns the symbol representation of the current object
95
- #
96
- # @return [Symbol] the symbol representation of the current object
97
- def to_sym
98
- to_s.parameterize.underscore.to_sym
99
- end
100
-
101
- # Returns whether the current object is equivalent to a given one. In addition
102
- # to {NoteKey} objects, the current object can be compared to a `Symbol`, a
103
- # `String` or anything coercible into one (via `#to_s`)
104
- #
105
- # @param other [NoteKey, Symbol, String, #to_s] the other object to compare to
106
- #
107
- # @return [Boolean] `true` if the objects are equivalent, `false` otherwise
108
- #
109
- # @example Comparing to another {NoteKey} object
110
- # note_key = GOBL::Org::NoteKey.new('goods')
111
- # note_key == GOBL::Org::NoteKey.new('goods') #=> true
112
- # note_key == GOBL::Org::NoteKey.new('payment') #=> false
113
- #
114
- # @example Comparing to a string
115
- # note_key = GOBL::Org::NoteKey.new('goods')
116
- # note_key == 'goods' #=> true
117
- # note_key == 'payment' #=> false
118
- #
119
- # @example Comparing to a symbol
120
- # note_key = GOBL::Org::NoteKey.new('goods')
121
- # note_key == :goods #=> true
122
- # note_key == :payment #=> false
123
- def ==(other)
124
- case other
125
- when self.class
126
- super
127
- when Symbol
128
- to_sym == other
129
- else
130
- to_s == other.to_s
131
- end
132
- end
133
-
134
- # Returns an array with all the enumerated objects of this type
135
- #
136
- # @return [Array<NoteKey>] the array of enumerated objects
137
- def self.all
138
- ENUM.keys.map { |key| new(key) }
139
- end
140
-
141
- # @api private
142
- def self.find_by_sym(sym)
143
- all.find { |object| object.to_sym == sym }
144
- end
145
-
146
- # @api private
147
- def self.find_by_inquirer(method_name)
148
- method_name =~ /(.+)\?$/ && find_by_sym(Regexp.last_match(1).to_sym)
149
- end
150
-
151
- # Returns the description of the current object
152
- #
153
- # @return [String] the description of the current object
154
- def description
155
- ENUM.fetch(_value, _value)
156
- end
157
-
158
- # @api private
159
- def respond_to_missing?(method_name, include_private = false)
160
- self.class.find_by_inquirer(method_name) || super
161
- end
162
-
163
- # Enables dynamic value inquirers like `NoteKey#goods?` for
164
- # each of the declared enum values (see {ENUM}). Each inquirer returns a
165
- # `Boolean` denoting whether the value equals the enquired value (`true`) or
166
- # not (`false`)
167
- #
168
- # @example
169
- # note_key = GOBL::Org::NoteKey.new('goods')
170
- # note_key.goods? # => true
171
- # note_key.payment? # => false
172
- def method_missing(method_name, *args, &block)
173
- if value = self.class.find_by_inquirer(method_name)
174
- self == value
175
- else
176
- super
177
- end
45
+ def strict_enum?
46
+ true
178
47
  end
179
48
  end
180
49
  end