Class: GOBL::ID

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(val) ⇒ GOBL::ID

Initializes a new GOBL::ID from a string URI



12
13
14
# File 'lib/gobl/id.rb', line 12

def initialize(val)
  @id = URI.parse(val)
end

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.

Parameters:

  • other (#to_s)

    another object to compare the current one with

Returns:

  • (Boolean)

    ‘true` if the given other can be considered equivalent to the current schema, `false` otherwise



76
77
78
# File 'lib/gobl/id.rb', line 76

def ==(other)
  to_s == other.to_s
end

#fragmentString

Returns the fragment part of the URI, without the ‘#’. This is usually used with schema references

Returns:

  • (String)

    the fragment part of the schema URI



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

Returns:

  • (Boolean)

    ‘true` if the current Schema ID represents a GOBL struct, `false` otherwise



20
21
22
# File 'lib/gobl/id.rb', line 20

def gobl?
  @id.host == 'gobl.org'
end

#moduleString

Returns the module components of the path as a single string.

Returns:

  • (String)

    the module components string



58
59
60
# File 'lib/gobl/id.rb', line 58

def module
  modules.join('/')
end

#modulesArray<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

Returns:

  • (Array<String>)

    the module components of the schema



51
52
53
# File 'lib/gobl/id.rb', line 51

def modules
  @id.path.split('/')[2..-2]
end

#nameString

Returns the name of the schema (by convention, the last element of a path)

Returns:

  • (String)

    the name of the schema



42
43
44
# File 'lib/gobl/id.rb', line 42

def name
  @id.path.split('/').last
end

#to_sString

Converts the schema into a ‘String`

Returns:

  • (String)

    the schema as a string



65
66
67
# File 'lib/gobl/id.rb', line 65

def to_s
  @id.to_s
end

#versionString

Returns the GOBL schema version

Returns:

  • (String)

    the schema version



35
36
37
# File 'lib/gobl/id.rb', line 35

def version
  @id.path.split('/')[1]
end