Class: GrowsurfRuby::Models::AffiliateApplication::Answer::Value

Inherits:
Object
  • Object
show all
Extended by:
Internal::Type::Converter, Internal::Util::SorbetRuntimeSupport
Defined in:
lib/growsurf_ruby/models/affiliate_application.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Internal::Type::Converter

coerce, dump, dump, inspect, inspect, meta_info, new_coerce_state, type_info

Methods included from Internal::Util::SorbetRuntimeSupport

const_missing, define_sorbet_constant!, sorbet_constant_defined?, to_sorbet_type

Constructor Details

#initialize(field_id: nil, label: nil, type: nil, value: nil) ⇒ Object

Some parameter documentations has been truncated, see GrowsurfRuby::Models::AffiliateApplication::Answer for more details.

Parameters:

  • field_id (String) (defaults to: nil)

    Stable key of the saved application-form field this answer belongs to.

  • label (String) (defaults to: nil)

    Customer-configured field label captured when the applicant submitted.

  • type (Symbol, GrowsurfRuby::Models::AffiliateApplication::Answer::Type) (defaults to: nil)

    Saved field type that determined how the scalar answer was validated.

  • value (String, Integer, Float, Boolean) (defaults to: nil)

    Applicant answer represented as one validated scalar.



171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/growsurf_ruby/models/affiliate_application.rb', line 171

class Value
  extend GrowsurfRuby::Internal::Type::Converter
  extend GrowsurfRuby::Internal::Util::SorbetRuntimeSupport

  private_class_method :new

  def self.===(other)
    scalar?(other)
  end

  def self.coerce(value, state:)
    matches = scalar?(value)
    state.fetch(:exactness)[matches ? :yes : :no] += 1
    state[:error] = ArgumentError.new("expected a string, number, or boolean") unless matches
    value
  end

  def self.to_sorbet_type
    T.any(String, Integer, Float, T::Boolean)
  end

  def self.scalar?(value)
    value.is_a?(String) ||
      value.is_a?(Integer) ||
      value.is_a?(Float) ||
      value == true ||
      value == false
  end
  private_class_method :scalar?
end

Class Method Details

.===(other) ⇒ Object



177
178
179
# File 'lib/growsurf_ruby/models/affiliate_application.rb', line 177

def self.===(other)
  scalar?(other)
end

.coerce(value, state:) ⇒ Object



181
182
183
184
185
186
# File 'lib/growsurf_ruby/models/affiliate_application.rb', line 181

def self.coerce(value, state:)
  matches = scalar?(value)
  state.fetch(:exactness)[matches ? :yes : :no] += 1
  state[:error] = ArgumentError.new("expected a string, number, or boolean") unless matches
  value
end

.to_sorbet_typeObject



188
189
190
# File 'lib/growsurf_ruby/models/affiliate_application.rb', line 188

def self.to_sorbet_type
  T.any(String, Integer, Float, T::Boolean)
end