Class: Natsuzora::Contract::AST::Scalar
- Defined in:
- lib/natsuzora/contract/ast/scalar.rb
Overview
Scalar value with type and modifier.
Defined Under Namespace
Modules: Modifier
Instance Attribute Summary collapse
-
#modifier ⇒ Object
readonly
Returns the value of attribute modifier.
-
#scalar_type ⇒ Object
readonly
Returns the value of attribute scalar_type.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #accepts?(data) ⇒ Boolean
-
#initialize(scalar_type, modifier = Modifier::NONE) ⇒ Scalar
constructor
A new instance of Scalar.
- #nullable? ⇒ Boolean
- #required? ⇒ Boolean
- #to_h ⇒ Object
Constructor Details
Instance Attribute Details
#modifier ⇒ Object (readonly)
Returns the value of attribute modifier.
21 22 23 |
# File 'lib/natsuzora/contract/ast/scalar.rb', line 21 def modifier @modifier end |
#scalar_type ⇒ Object (readonly)
Returns the value of attribute scalar_type.
21 22 23 |
# File 'lib/natsuzora/contract/ast/scalar.rb', line 21 def scalar_type @scalar_type end |
Instance Method Details
#==(other) ⇒ Object
52 53 54 55 56 |
# File 'lib/natsuzora/contract/ast/scalar.rb', line 52 def ==(other) other.is_a?(Scalar) && other.scalar_type == @scalar_type && other.modifier == @modifier end |
#accepts?(data) ⇒ Boolean
37 38 39 40 41 42 43 44 |
# File 'lib/natsuzora/contract/ast/scalar.rb', line 37 def accepts?(data) case @scalar_type when ScalarType::STRING then data.is_a?(String) when ScalarType::INTEGER then data.is_a?(Integer) when ScalarType::BOOL then data.is_a?(TrueClass) || data.is_a?(FalseClass) when ScalarType::SCALAR then data.is_a?(String) || data.is_a?(Integer) end end |
#nullable? ⇒ Boolean
29 30 31 |
# File 'lib/natsuzora/contract/ast/scalar.rb', line 29 def nullable? @modifier == Modifier::NULLABLE end |