Module: Apify::SchemaHelper

Defined in:
lib/apify/schema_helper.rb

Instance Method Summary collapse

Instance Method Details

#array(items = nil) ⇒ Object



14
15
16
17
18
# File 'lib/apify/schema_helper.rb', line 14

def array(items = nil)
  { 'type' => 'array' }.tap do |schema|
    schema['items'] = items if items
  end
end

#booleanObject



24
25
26
# File 'lib/apify/schema_helper.rb', line 24

def boolean
  { 'type' => 'boolean' }
end

#emailObject



50
51
52
53
# File 'lib/apify/schema_helper.rb', line 50

def email
  { 'type' => 'string',
    'pattern' => Apify::Patterns::EMAIL.source }
end

#enum(schema, allowed_values) ⇒ Object



28
29
30
# File 'lib/apify/schema_helper.rb', line 28

def enum(schema, allowed_values)
  schema.merge('enum' => allowed_values)
end

#integerObject



36
37
38
# File 'lib/apify/schema_helper.rb', line 36

def integer
  { 'type' => 'integer' }
end

#numberObject



32
33
34
# File 'lib/apify/schema_helper.rb', line 32

def number
  { 'type' => 'number' }
end

#object(properties = nil) ⇒ Object



8
9
10
11
12
# File 'lib/apify/schema_helper.rb', line 8

def object(properties = nil)
  { 'type' => 'object' }.tap do |schema|
    schema['properties'] = properties if properties
  end
end

#optional(schema) ⇒ Object



4
5
6
# File 'lib/apify/schema_helper.rb', line 4

def optional(schema)
  schema.merge('optional' => true)
end

#sql_dateObject



40
41
42
43
# File 'lib/apify/schema_helper.rb', line 40

def sql_date
  { 'type' => 'string',
    'pattern' => Apify::Patterns::SQL_DATE.source }
end

#sql_datetimeObject



45
46
47
48
# File 'lib/apify/schema_helper.rb', line 45

def sql_datetime
  { 'type' => 'string',
    'pattern' => Apify::Patterns::SQL_DATETIME.source }
end

#stringObject



20
21
22
# File 'lib/apify/schema_helper.rb', line 20

def string
  { 'type' => 'string' }
end

#urlObject



55
56
57
58
# File 'lib/apify/schema_helper.rb', line 55

def url
  { 'type' => 'string',
    'pattern' => Apify::Patterns::URL.source }
end