Class: ShafClient::Field

Inherits:
Object
  • Object
show all
Defined in:
lib/shaf_client/field.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, prompt: nil, title: nil, required: false, read_only: false, hidden: false, templated: false, type: nil, value: nil, regex: nil) ⇒ Field

Returns a new instance of Field.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/shaf_client/field.rb', line 8

def initialize(
  name:,
  prompt: nil,
  title: nil,
  required: false,
  read_only: false,
  hidden: false,
  templated: false,
  type: nil,
  value: nil,
  regex: nil
)
  @name = name.to_sym
  @prompt = prompt || title || name
  @required = required
  @read_only = read_only
  @hidden = hidden
  @templated = templated
  @type = type&.downcase
  @value = value
  @regex = parse_regexp(regex)
end

Instance Attribute Details

#hiddenObject (readonly)

Returns the value of attribute hidden.



5
6
7
# File 'lib/shaf_client/field.rb', line 5

def hidden
  @hidden
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/shaf_client/field.rb', line 5

def name
  @name
end

#promptObject (readonly)

Returns the value of attribute prompt.



5
6
7
# File 'lib/shaf_client/field.rb', line 5

def prompt
  @prompt
end

#read_onlyObject (readonly)

Returns the value of attribute read_only.



5
6
7
# File 'lib/shaf_client/field.rb', line 5

def read_only
  @read_only
end

#regexObject (readonly)

Returns the value of attribute regex.



5
6
7
# File 'lib/shaf_client/field.rb', line 5

def regex
  @regex
end

#requiredObject (readonly)

Returns the value of attribute required.



5
6
7
# File 'lib/shaf_client/field.rb', line 5

def required
  @required
end

#templatedObject (readonly)

Returns the value of attribute templated.



5
6
7
# File 'lib/shaf_client/field.rb', line 5

def templated
  @templated
end

#typeObject (readonly)

Returns the value of attribute type.



5
6
7
# File 'lib/shaf_client/field.rb', line 5

def type
  @type
end

#valueObject (readonly)

Returns the value of attribute value.



5
6
7
# File 'lib/shaf_client/field.rb', line 5

def value
  @value
end

Instance Method Details

#valid?(value) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
34
35
36
37
# File 'lib/shaf_client/field.rb', line 31

def valid?(value)
  return false unless validate_required(value)
  return false unless validate_number(value)
  return false unless validate_string(value)
  return false unless validate_regexp(value)
  true
end