Class: ActiveList::Definition::DataColumn
- Inherits:
-
AbstractColumn
- Object
- AbstractColumn
- ActiveList::Definition::DataColumn
- Defined in:
- lib/active_list/definition/data_column.rb
Direct Known Subclasses
Constant Summary collapse
- LABELS_COLUMNS =
[:full_name, :label, :name, :number, :coordinate]
Instance Attribute Summary
Attributes inherited from AbstractColumn
Instance Method Summary collapse
-
#datatype ⇒ Object
Returns the data type of the column if the column is in the database.
- #enumerize? ⇒ Boolean
-
#exportable? ⇒ Boolean
Defines if column is exportable.
-
#exporting_datum_code(record = 'record_of_the_death', noview = false) ⇒ Object
Code for exportation.
- #header_code ⇒ Object
-
#limit ⇒ Object
Returns the size/length of the column if the column is in the database.
- #numeric? ⇒ Boolean
-
#record_expr(record = 'record_of_the_death') ⇒ Object
Generate code in order to get the (foreign) record of the column.
- #sort_expression ⇒ Object
-
#sortable? ⇒ Boolean
Check if a column is sortable.
Methods inherited from AbstractColumn
#check_options!, #hidden?, #initialize, #short_id, #unique_id
Constructor Details
This class inherits a constructor from ActiveList::Definition::AbstractColumn
Instance Method Details
#datatype ⇒ Object
Returns the data type of the column if the column is in the database
45 46 47 |
# File 'lib/active_list/definition/data_column.rb', line 45 def datatype @options[:datatype] || (@column ? @column.type : nil) end |
#enumerize? ⇒ Boolean
50 51 52 |
# File 'lib/active_list/definition/data_column.rb', line 50 def enumerize? return false end |
#exportable? ⇒ Boolean
Defines if column is exportable
64 65 66 |
# File 'lib/active_list/definition/data_column.rb', line 64 def exportable? true end |
#exporting_datum_code(record = 'record_of_the_death', noview = false) ⇒ Object
Code for exportation
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/active_list/definition/data_column.rb', line 18 def exporting_datum_code(record='record_of_the_death', noview=false) datum = self.datum_code(record) if self.datatype == :boolean datum = "(#{datum} ? ::I18n.translate('list.export.true_value') : ::I18n.translate('list.export.false_value'))" elsif self.datatype == :date datum = "(#{datum}.nil? ? '' : #{datum}.l)" elsif self.datatype == :decimal and not noview currency = nil if currency = self.[:currency] currency = currency[:body] if currency.is_a?(Hash) currency = :currency if currency.is_a?(TrueClass) currency = "#{record}.#{currency}".c if currency.is_a?(Symbol) end datum = "(#{datum}.nil? ? '' : #{datum}.l(#{'currency: ' + currency.inspect if currency}))" elsif @name.to_s.match(/(^|\_)currency$/) and self.datatype == :string datum = "(Nomen::Currencies[#{datum}] ? Nomen::Currencies[#{datum}].human_name : '')" elsif @name.to_s.match(/(^|\_)country$/) and self.datatype == :string datum = "(Nomen::Countries[#{datum}] ? Nomen::Countries[#{datum}].human_name : '')" elsif @name.to_s.match(/(^|\_)language$/) and self.datatype == :string datum = "(Nomen::Languages[#{datum}] ? Nomen::Languages[#{datum}].human_name : '')" elsif self.enumerize? datum = "(#{datum}.nil? ? '' : #{datum}.text)" end return datum end |
#header_code ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/active_list/definition/data_column.rb', line 9 def header_code if @options[:label] "#{@options[:label].to_s.strip.inspect}.t(scope: 'labels')".c else "#{@table.model.name}.human_attribute_name(#{@name.inspect})".c end end |
#limit ⇒ Object
Returns the size/length of the column if the column is in the database
59 60 61 |
# File 'lib/active_list/definition/data_column.rb', line 59 def limit @column[:limit] if @column end |
#numeric? ⇒ Boolean
54 55 56 |
# File 'lib/active_list/definition/data_column.rb', line 54 def numeric? [:decimal, :integer, :float, :numeric].include? self.datatype end |
#record_expr(record = 'record_of_the_death') ⇒ Object
Generate code in order to get the (foreign) record of the column
76 77 78 |
# File 'lib/active_list/definition/data_column.rb', line 76 def record_expr(record = 'record_of_the_death') return record end |
#sort_expression ⇒ Object
80 81 82 |
# File 'lib/active_list/definition/data_column.rb', line 80 def sort_expression raise NotImplementedError, "sort_expression must be implemented" end |
#sortable? ⇒ Boolean
Check if a column is sortable
69 70 71 72 73 |
# File 'lib/active_list/definition/data_column.rb', line 69 def sortable? return true # not self.action? and not self.[:through] and not @column.nil? end |