Class: Axiom::Attribute::String

Inherits:
Object show all
Includes:
Comparable, Function::Predicate::Match::Methods, Function::Predicate::NoMatch::Methods
Defined in:
lib/axiom/attribute/string.rb

Overview

Represents a String value in a relation tuple

Constant Summary collapse

DEFAULT_MIN_LENGTH =
0
DEFAULT_MAX_LENGTH =
50

Instance Attribute Summary collapse

Attributes inherited from Axiom::Attribute

#name

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Comparable

#asc, #desc

Methods included from Function::Predicate::GreaterThan::Methods

#gt

Methods included from Function::Predicate::GreaterThanOrEqualTo::Methods

#gte

Methods included from Function::Predicate::LessThan::Methods

#lt

Methods included from Function::Predicate::LessThanOrEqualTo::Methods

#lte

Methods included from Axiom::Aggregate::Minimum::Methods

#minimum

Methods included from Axiom::Aliasable

#inheritable_alias

Methods included from Axiom::Aggregate::Maximum::Methods

#maximum

Methods included from Axiom::Aggregate::Mean::Methods

#mean

Methods included from Axiom::Aggregate::Variance::Methods

#variance

Methods included from Axiom::Aggregate::StandardDeviation::Methods

#standard_deviation

Methods included from Function::Predicate::Match::Methods

#match

Methods included from Function::Predicate::NoMatch::Methods

#no_match

Methods included from Function::Predicate::Equality::Methods

#eq

Methods included from Function::Predicate::Exclusion::Methods

#exclude

Methods included from Function::Predicate::Inequality::Methods

#ne

Methods included from Function::Predicate::Inclusion::Methods

#include

Methods included from Axiom::Aggregate::Count::Methods

#count

Methods inherited from Axiom::Attribute

#call, coerce, infer_type, name_from, #rename, #required?, #type, #valid_primitive?

Methods included from Visitable

#accept

Constructor Details

#initialize(_name, _options = EMPTY_HASH) ⇒ undefined

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initialize a String Attribute

Parameters:

  • _name (#to_sym)

    the attribute name

  • _options (#to_hash) (defaults to: EMPTY_HASH)

    the options for the attribute

  • options (Hash)

    a customizable set of options



64
65
66
67
68
# File 'lib/axiom/attribute/string.rb', line 64

def initialize(_name, _options = EMPTY_HASH)
  super
  @min_length = @options.fetch(:min_length, DEFAULT_MIN_LENGTH)
  @max_length = @options.fetch(:max_length, DEFAULT_MAX_LENGTH)
end

Instance Attribute Details

#max_length::Integer (readonly)

The maximum string length for a valid value

Examples:

string.max_length  # => 50

Returns:

  • (::Integer)


34
35
36
# File 'lib/axiom/attribute/string.rb', line 34

def max_length
  @max_length
end

#min_length::Integer (readonly)

The minimum string length for a valid value

Examples:

string.min_length  # => 0

Returns:

  • (::Integer)


24
25
26
# File 'lib/axiom/attribute/string.rb', line 24

def min_length
  @min_length
end

Class Method Details

.primitiveClass<::String>

The String primitive

Examples:

String.primitive  # => ::String

Returns:



44
45
46
# File 'lib/axiom/attribute/string.rb', line 44

def self.primitive
  ::String
end

Instance Method Details

#valid_value?(value) ⇒ Boolean

Test if the value matches the attribute constraints

Examples:

string.valid_value?(value)  # => true or false

Parameters:

  • value (Object)

    the value to test

Returns:



81
82
83
# File 'lib/axiom/attribute/string.rb', line 81

def valid_value?(value)
  valid_or_optional?(value) { super && valid_length?(value) }
end