Class: Structor::Type
- Inherits:
-
Object
- Object
- Structor::Type
- Defined in:
- lib/structor/type.rb
Constant Summary collapse
- TYPE_MAP =
{ string: String, number: Numeric, array: Array, hash: Hash, boolean: [TrueClass, FalseClass] }
Instance Method Summary collapse
- #check(value) ⇒ Object
- #describe ⇒ Object
-
#initialize(specification) ⇒ Type
constructor
A new instance of Type.
Constructor Details
#initialize(specification) ⇒ Type
3 4 5 6 7 |
# File 'lib/structor/type.rb', line 3 def initialize(specification) @specification = Array(specification) .map { |type| TYPE_MAP[type] || type } .flatten end |
Instance Method Details
#check(value) ⇒ Object
17 18 19 |
# File 'lib/structor/type.rb', line 17 def check(value) @specification.any? { |type| value.is_a?(type) } end |
#describe ⇒ Object
21 22 23 |
# File 'lib/structor/type.rb', line 21 def describe @specification.map(&:name).join('|') end |