Class: Axiom::Attribute::Numeric

Inherits:
Object show all
Includes:
Axiom::Aggregate::Sum::Methods, Comparable
Defined in:
lib/axiom/attribute/numeric.rb

Overview

Represents a Numeric value in a relation tuple

Direct Known Subclasses

Decimal, Float, Integer

Constant Summary collapse

DEFAULT_SIZE =
(-::Float::INFINITY..::Float::INFINITY).freeze

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 Axiom::Aggregate::Sum::Methods

#sum

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 Numeric 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



52
53
54
55
# File 'lib/axiom/attribute/numeric.rb', line 52

def initialize(_name, _options = EMPTY_HASH)
  super
  @size = @options.fetch(:size, self.class::DEFAULT_SIZE).to_inclusive
end

Instance Attribute Details

#sizeRange<::Numeric> (readonly)

The Numeric range for a valid value

Examples:

numeric.size  # => 0..10

Returns:



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

def size
  @size
end

Class Method Details

.primitiveClass<::Numeric>

The Numeric primitive

Examples:

Numeric.primitive  # => ::Numeric

Returns:



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

def self.primitive
  ::Numeric
end

Instance Method Details

#valid_value?(value) ⇒ Boolean

Test if the value matches the attribute constraints

Examples:

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

Parameters:

  • value (Object)

    the value to test

Returns:



68
69
70
# File 'lib/axiom/attribute/numeric.rb', line 68

def valid_value?(value)
  valid_or_optional?(value) { super && size.cover?(value) }
end