-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from theodi/feature-add-field
Add `Field` class
- Loading branch information
Showing
16 changed files
with
256 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
module JsonTableSchema | ||
class Field < Hash | ||
include JsonTableSchema::Helpers | ||
|
||
attr_reader :type_class | ||
|
||
def initialize(descriptor) | ||
self.merge! descriptor | ||
@type_class = get_type | ||
end | ||
|
||
def name | ||
self['name'] | ||
end | ||
|
||
def type | ||
self['type'] || 'string' | ||
end | ||
|
||
def format | ||
self['format'] || 'default' | ||
end | ||
|
||
def constraints | ||
self['constraints'] || {} | ||
end | ||
|
||
def cast_value(col) | ||
klass = get_class_for_type(type) | ||
converter = Kernel.const_get(klass).new(self) | ||
converter.cast(col) | ||
end | ||
|
||
private | ||
|
||
def get_type | ||
Object.const_get get_class_for_type(type) | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module JsonTableSchema | ||
VERSION = "0.1.0" | ||
VERSION = "0.2.0" | ||
end |
Oops, something went wrong.