Module: Jacoat::Detector

Defined in:
lib/jacoat/detector.rb

Class Method Summary collapse

Class Method Details

.is_compound?(hash) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/jacoat/detector.rb', line 10

def self.is_compound?(hash)
  return true if hash.has_key?(:data) and hash.has_key?(:included) and hash[:data].is_a?(Array)
end

.is_document?(hash) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
17
18
# File 'lib/jacoat/detector.rb', line 14

def self.is_document?(hash)
  return true if hash.has_key?(:data) and !hash[:data].is_a?(Array)
  return true if hash.has_key?(:errors)
  return true if hash.has_key?(:meta)
end

.is_resource?(hash) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
30
31
32
33
34
35
# File 'lib/jacoat/detector.rb', line 27

def self.is_resource?(hash)
  # resource when parsing (must have id)
  return true if hash.has_key?(:type) &&
                 hash.has_key?(:id) &&
                 hash.has_key?(:attributes)
  # or a resource when being created (without id)
  return true if hash.has_key?(:type) &&
                 hash.has_key?(:attributes)
end

.is_resource_identifier?(hash) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
24
25
# File 'lib/jacoat/detector.rb', line 20

def self.is_resource_identifier?(hash)
  return true if hash.has_key?(:type) &&
                 hash.has_key?(:id) &&
                 !hash.has_key?(:attributes)
                 !hash.has_key?(:relationships)
end

.what_is(hash) ⇒ Object



3
4
5
6
7
8
# File 'lib/jacoat/detector.rb', line 3

def self.what_is(hash)
  return "compound" if is_compound?(hash)
  return "document" if is_document?(hash)
  return "resource" if is_resource?(hash)
  return "resource_identifier" if is_resource_identifier?(hash)
end