Class: Census::DataType
- Inherits:
-
Object
- Object
- Census::DataType
- Defined in:
- lib/census/data_type.rb
Constant Summary collapse
- @@data_types =
[]
Instance Attribute Summary collapse
-
#format_data ⇒ Object
Returns the value of attribute format_data.
-
#name ⇒ Object
Returns the value of attribute name.
-
#sql_transform ⇒ Object
Returns the value of attribute sql_transform.
-
#validate_data ⇒ Object
Returns the value of attribute validate_data.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name, options) ⇒ DataType
constructor
A new instance of DataType.
- #to_s ⇒ Object
Constructor Details
#initialize(name, options) ⇒ DataType
Returns a new instance of DataType.
22 23 24 25 26 27 |
# File 'lib/census/data_type.rb', line 22 def initialize(name, ) @name = name @sql_transform = [:sql_transform] || lambda {|column_name| "#{column_name}"} @format_data = [:format_data] || lambda {|data| data} @validate_data = [:validate_data] || lambda {|data| nil} end |
Instance Attribute Details
#format_data ⇒ Object
Returns the value of attribute format_data.
5 6 7 |
# File 'lib/census/data_type.rb', line 5 def format_data @format_data end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/census/data_type.rb', line 3 def name @name end |
#sql_transform ⇒ Object
Returns the value of attribute sql_transform.
4 5 6 |
# File 'lib/census/data_type.rb', line 4 def sql_transform @sql_transform end |
#validate_data ⇒ Object
Returns the value of attribute validate_data.
6 7 8 |
# File 'lib/census/data_type.rb', line 6 def validate_data @validate_data end |
Class Method Details
.all ⇒ Object
10 11 12 |
# File 'lib/census/data_type.rb', line 10 def self.all @@data_types end |
.define(name, options = {}) ⇒ Object
14 15 16 |
# File 'lib/census/data_type.rb', line 14 def self.define(name, = {}) @@data_types << DataType.new(name, ) end |
.find(name) ⇒ Object
18 19 20 |
# File 'lib/census/data_type.rb', line 18 def self.find(name) @@data_types.select {|dt| dt.name == name}.try(:first) end |
Instance Method Details
#to_s ⇒ Object
29 30 31 |
# File 'lib/census/data_type.rb', line 29 def to_s @name end |