Class: TableSchema::Types::Base
- Inherits:
-
Object
- Object
- TableSchema::Types::Base
- Includes:
- Helpers
- Defined in:
- lib/tableschema/types/base.rb
Direct Known Subclasses
Any, Array, Boolean, Date, DateTime, Duration, GeoJSON, GeoPoint, Integer, Number, Object, String, Time, Year, YearMonth
Instance Method Summary collapse
- #cast(value) ⇒ Object
-
#initialize(field) ⇒ Base
constructor
A new instance of Base.
- #test(value) ⇒ Object
Methods included from Helpers
#deep_symbolize_keys, #get_class_for_type, #type_class_lookup
Constructor Details
#initialize(field) ⇒ Base
Returns a new instance of Base.
8 9 10 11 |
# File 'lib/tableschema/types/base.rb', line 8 def initialize(field) @field = field set_format end |
Instance Method Details
#cast(value) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/tableschema/types/base.rb', line 13 def cast(value) send("cast_#{@format}", value) rescue NoMethodError => e if e..start_with?('undefined method `cast_') raise(TableSchema::InvalidFormat.new("The format `#{@format}` is not supported by the type `#{@type}`")) else raise e end end |
#test(value) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/tableschema/types/base.rb', line 23 def test(value) cast(value) true rescue TableSchema::Exception false end |