class RDStation::Builder::Field

More info: developers.rdstation.com/pt-BR/reference/fields#methodPostDetails

Constants

DATA_TYPES
PRESENTATION_TYPES
REQUIRED_FIELDS

Public Class Methods

new(api_identifier) click to toggle source
# File lib/rdstation/builder/field.rb, line 14
def initialize(api_identifier)
  raise 'api_identifier required' unless api_identifier
  unless valid_identifier(api_identifier)
    raise 'api_identifier is not in a valid format, need start with "cf_"'
  end

  @values = {}
  @values['api_identifier'] = api_identifier
end

Public Instance Methods

build() click to toggle source
# File lib/rdstation/builder/field.rb, line 54
def build
  empty_fields = REQUIRED_FIELDS.select { |field| @values[field].nil? }
  unless empty_fields.empty?
    raise "Required fields are missing - #{empty_fields}"
  end

  @values
end
data_type(data_type) click to toggle source
# File lib/rdstation/builder/field.rb, line 24
def data_type(data_type)
  raise "Not valid data_type - #{DATA_TYPES}" unless DATA_TYPES.include? data_type

  @values['data_type'] = data_type
end
label(language, label) click to toggle source
# File lib/rdstation/builder/field.rb, line 38
def label(language, label)
  @values['label'] = { language.to_s => label }
end
name(language, name) click to toggle source
# File lib/rdstation/builder/field.rb, line 42
def name(language, name)
  @values['name'] = { language.to_s => name }
end
presentation_type(presentation_type) click to toggle source
# File lib/rdstation/builder/field.rb, line 30
def presentation_type(presentation_type)
  unless PRESENTATION_TYPES.include? presentation_type
    raise "Not valid presentation_type - #{PRESENTATION_TYPES}"
  end

  @values['presentation_type'] = presentation_type
end
valid_options(valid_options) click to toggle source
# File lib/rdstation/builder/field.rb, line 50
def valid_options(valid_options)
  @values['valid_options'] = valid_options
end
validation_rules(validation_rules) click to toggle source
# File lib/rdstation/builder/field.rb, line 46
def validation_rules(validation_rules)
  @values['validation_rules'] = validation_rules
end

Private Instance Methods

valid_identifier(api_identifier) click to toggle source
# File lib/rdstation/builder/field.rb, line 65
def valid_identifier(api_identifier)
  api_identifier.start_with? 'cf_'
end