Class: Pgerd::Column
Constant Summary collapse
- ID =
%w(id)
- GROUPS =
%i(id other timestamps)
Instance Attribute Summary collapse
-
#data_type ⇒ Object
Returns the value of attribute data_type.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #abbreviated_data_type ⇒ Object
- #group ⇒ Object
- #group_for_sorting ⇒ Object
-
#initialize(name, data_type) ⇒ Column
constructor
A new instance of Column.
- #to_a_for_sorting ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name, data_type) ⇒ Column
Returns a new instance of Column.
8 9 10 11 |
# File 'lib/pgerd/column.rb', line 8 def initialize(name, data_type) @name = name @data_type = data_type end |
Instance Attribute Details
#data_type ⇒ Object
Returns the value of attribute data_type.
4 5 6 |
# File 'lib/pgerd/column.rb', line 4 def data_type @data_type end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/pgerd/column.rb', line 4 def name @name end |
Instance Method Details
#<=>(other) ⇒ Object
13 14 15 |
# File 'lib/pgerd/column.rb', line 13 def <=>(other) to_a_for_sorting <=> other.to_a_for_sorting end |
#abbreviated_data_type ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/pgerd/column.rb', line 31 def abbreviated_data_type # The SQL standard requires that writing just timestamp be equivalent to timestamp without time zone, # and PostgreSQL honors that behavior. @data_type .gsub('timestamp without time zone', 'timestamp') .gsub(/\bwithout\b/, 'w/o') .gsub(/\bwith\b/, 'w/') end |
#group ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/pgerd/column.rb', line 17 def group if ID.include? @name :id elsif @data_type.include?("timestamp") :timestamps else :other end end |
#group_for_sorting ⇒ Object
27 28 29 |
# File 'lib/pgerd/column.rb', line 27 def group_for_sorting GROUPS.index(group) end |
#to_a_for_sorting ⇒ Object
44 45 46 |
# File 'lib/pgerd/column.rb', line 44 def to_a_for_sorting [group_for_sorting, name, data_type] end |
#to_s ⇒ Object
40 41 42 |
# File 'lib/pgerd/column.rb', line 40 def to_s "#{name} [label = <>]" end |