Class: GOBL::ID
- Inherits:
-
Object
- Object
- GOBL::ID
- Defined in:
- lib/gobl/id.rb
Overview
Provide a wrapper around Schema IDs (URLs) so that it’s easy to extract the type of document we’re dealing with
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Returns whether the current schema is equivalent to a given object.
-
#fragment ⇒ String
Returns the fragment part of the URI, without the ‘#’.
-
#gobl? ⇒ Boolean
Returns whether the current schema ID represents a GOBL struct or not.
-
#initialize(val) ⇒ GOBL::ID
constructor
Initializes a new ID from a string URI.
-
#module ⇒ String
Returns the module components of the path as a single string.
-
#modules ⇒ Array<String>
Returns the module components of the path, which may be empty.
-
#name ⇒ String
Returns the name of the schema (by convention, the last element of a path).
-
#to_s ⇒ String
Converts the schema into a ‘String`.
-
#version ⇒ String
Returns the GOBL schema version.
Constructor Details
Instance Method Details
#==(other) ⇒ Boolean
Returns whether the current schema is equivalent to a given object. Any object that can be coerced into a string via ‘#to_s` can be provided.
76 77 78 |
# File 'lib/gobl/id.rb', line 76 def ==(other) to_s == other.to_s end |
#fragment ⇒ String
Returns the fragment part of the URI, without the ‘#’. This is usually used with schema references
28 29 30 |
# File 'lib/gobl/id.rb', line 28 def fragment @id.fragment end |
#gobl? ⇒ Boolean
Returns whether the current schema ID represents a GOBL struct or not
20 21 22 |
# File 'lib/gobl/id.rb', line 20 def gobl? @id.host == 'gobl.org' end |
#module ⇒ String
Returns the module components of the path as a single string.
58 59 60 |
# File 'lib/gobl/id.rb', line 58 def module modules.join('/') end |
#modules ⇒ Array<String>
Returns the module components of the path, which may be empty. The last element of the path is always considered the name of the current schema, and not the module
51 52 53 |
# File 'lib/gobl/id.rb', line 51 def modules @id.path.split('/')[2..-2] end |
#name ⇒ String
Returns the name of the schema (by convention, the last element of a path)
42 43 44 |
# File 'lib/gobl/id.rb', line 42 def name @id.path.split('/').last end |
#to_s ⇒ String
Converts the schema into a ‘String`
65 66 67 |
# File 'lib/gobl/id.rb', line 65 def to_s @id.to_s end |
#version ⇒ String
Returns the GOBL schema version
35 36 37 |
# File 'lib/gobl/id.rb', line 35 def version @id.path.split('/')[1] end |