Class: Diva::Type::AtomicType

Inherits:
MetaType
  • Object
show all
Defined in:
lib/diva/type.rb

Direct Known Subclasses

TimeType

Instance Attribute Summary

Attributes inherited from MetaType

#name

Instance Method Summary collapse

Methods inherited from MetaType

#cast, #dump_for_json, #inspect, #to_s

Constructor Details

#initialize(name, recommended_class, *rest, &cast) ⇒ AtomicType

Returns a new instance of AtomicType.



81
82
83
84
# File 'lib/diva/type.rb', line 81

def initialize(name, recommended_class, *rest, &cast)
  super(name, *rest, &cast)
  @recommended_classes = Array(recommended_class)
end

Instance Method Details

#recommendation_point(value) ⇒ Object



86
87
88
89
# File 'lib/diva/type.rb', line 86

def recommendation_point(value)
  _, point = @recommended_classes.map.with_index { |k, i| [k, i] }.find { |k, _| value.is_a?(k) }
  point
end

#schemaObject



91
92
93
# File 'lib/diva/type.rb', line 91

def schema
  @schema ||= { type: uri }.freeze
end

#uriObject



95
96
97
# File 'lib/diva/type.rb', line 95

def uri
  @uri ||= Diva::URI("diva://atomic.type/#{name}")
end