Module: NotionRb::Utils::UuidValidator

Included in:
Block
Defined in:
lib/notion_rb/utils/uuid_validator.rb

Instance Method Summary collapse

Instance Method Details

#parse_from_hex(hex) ⇒ Object

Raises:

  • (ArgumentError)


21
22
23
24
25
26
27
28
29
# File 'lib/notion_rb/utils/uuid_validator.rb', line 21

def parse_from_hex(hex)
  raise ArgumentError, 'Incorrect hex size, must be equal to 32' unless hex.size == 32

  [20, 16, 12, 8].each do |position|
    hex = hex.to_s.insert(position, '-')
  end

  hex
end

#parse_from_url(url) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/notion_rb/utils/uuid_validator.rb', line 13

def parse_from_url(url)
  if url.match? %r{https?://[\S]+}
    url.split('/')[-1].split('?')[0].split('-')[-1][0..31]
  else
    url
  end
end

#parse_uuid(url_or_uuid) ⇒ Object



6
7
8
9
10
11
# File 'lib/notion_rb/utils/uuid_validator.rb', line 6

def parse_uuid(url_or_uuid)
  uuid = parse_from_url url_or_uuid
  hex = uuid.delete('-')

  parse_from_hex(hex)
end