Class: Bagman::SimpleColumn
- Inherits:
-
ActiveRecord::ConnectionAdapters::Column
- Object
- ActiveRecord::ConnectionAdapters::Column
- Bagman::SimpleColumn
- Defined in:
- lib/bagman/simple_column.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
- .dd_mm_yyyy_to_date(string) ⇒ Object
- .dd_mm_yyyy_to_time(string) ⇒ Object
- .string_to_date(string) ⇒ Object
- .string_to_time(string) ⇒ Object
Instance Method Summary collapse
- #index? ⇒ Boolean
- #index_name ⇒ Object
-
#initialize(name, role, type, options = {}) ⇒ SimpleColumn
constructor
A new instance of SimpleColumn.
- #type_cast(value) ⇒ Object
Constructor Details
#initialize(name, role, type, options = {}) ⇒ SimpleColumn
Returns a new instance of SimpleColumn.
8 9 10 |
# File 'lib/bagman/simple_column.rb', line 8 def initialize(name, role, type, ={}) @name, @role, @type, @options = name, role, type, end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/bagman/simple_column.rb', line 6 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/bagman/simple_column.rb', line 6 def @options end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
6 7 8 |
# File 'lib/bagman/simple_column.rb', line 6 def type @type end |
Class Method Details
.dd_mm_yyyy_to_date(string) ⇒ Object
38 39 40 |
# File 'lib/bagman/simple_column.rb', line 38 def self.dd_mm_yyyy_to_date(string) Date.strptime(string, "%d/%m/%Y") rescue nil end |
.dd_mm_yyyy_to_time(string) ⇒ Object
46 47 48 |
# File 'lib/bagman/simple_column.rb', line 46 def self.dd_mm_yyyy_to_time(string) DateTime.strptime(string, "%d/%m/%Y") rescue nil end |
.string_to_date(string) ⇒ Object
34 35 36 |
# File 'lib/bagman/simple_column.rb', line 34 def self.string_to_date(string) dd_mm_yyyy_to_date(string) || super end |
.string_to_time(string) ⇒ Object
42 43 44 |
# File 'lib/bagman/simple_column.rb', line 42 def self.string_to_time(string) dd_mm_yyyy_to_time(string) || super end |
Instance Method Details
#index? ⇒ Boolean
30 31 32 |
# File 'lib/bagman/simple_column.rb', line 30 def index? !! index_name end |
#index_name ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/bagman/simple_column.rb', line 21 def index_name case [:index] when TrueClass "index_#{name}" when String,Symbol [:index] end end |
#type_cast(value) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/bagman/simple_column.rb', line 12 def type_cast(value) case type when Class type.new(value) else super end end |