Class: Pcrd::Schema::Column
- Inherits:
-
Object
- Object
- Pcrd::Schema::Column
- Defined in:
- lib/pcrd/schema/column.rb
Instance Attribute Summary collapse
-
#alignment ⇒ Object
readonly
Returns the value of attribute alignment.
-
#attnum ⇒ Object
readonly
Returns the value of attribute attnum.
-
#default_expr ⇒ Object
readonly
Returns the value of attribute default_expr.
-
#fixed_size ⇒ Object
readonly
Returns the value of attribute fixed_size.
-
#formatted_type ⇒ Object
readonly
Returns the value of attribute formatted_type.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#nullable ⇒ Object
readonly
Returns the value of attribute nullable.
-
#type_name ⇒ Object
readonly
Returns the value of attribute type_name.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #display_alignment ⇒ Object
- #display_size ⇒ Object
-
#display_type ⇒ Object
Human-readable type string, with common verbose PG names shortened.
- #fixed? ⇒ Boolean
-
#initialize(attnum:, name:, type_name:, formatted_type:, alignment:, fixed_size:, nullable:, default_expr:) ⇒ Column
constructor
alignment: Integer (1, 2, 4, or 8 bytes) fixed_size: Integer bytes, or nil for variable-length.
- #inspect ⇒ Object
- #variable? ⇒ Boolean
Constructor Details
#initialize(attnum:, name:, type_name:, formatted_type:, alignment:, fixed_size:, nullable:, default_expr:) ⇒ Column
alignment: Integer (1, 2, 4, or 8 bytes) fixed_size: Integer bytes, or nil for variable-length
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/pcrd/schema/column.rb', line 11 def initialize(attnum:, name:, type_name:, formatted_type:, alignment:, fixed_size:, nullable:, default_expr:) @attnum = attnum @name = name @type_name = type_name @formatted_type = formatted_type @alignment = alignment @fixed_size = fixed_size @nullable = nullable @default_expr = default_expr end |
Instance Attribute Details
#alignment ⇒ Object (readonly)
Returns the value of attribute alignment.
6 7 8 |
# File 'lib/pcrd/schema/column.rb', line 6 def alignment @alignment end |
#attnum ⇒ Object (readonly)
Returns the value of attribute attnum.
6 7 8 |
# File 'lib/pcrd/schema/column.rb', line 6 def attnum @attnum end |
#default_expr ⇒ Object (readonly)
Returns the value of attribute default_expr.
6 7 8 |
# File 'lib/pcrd/schema/column.rb', line 6 def default_expr @default_expr end |
#fixed_size ⇒ Object (readonly)
Returns the value of attribute fixed_size.
6 7 8 |
# File 'lib/pcrd/schema/column.rb', line 6 def fixed_size @fixed_size end |
#formatted_type ⇒ Object (readonly)
Returns the value of attribute formatted_type.
6 7 8 |
# File 'lib/pcrd/schema/column.rb', line 6 def formatted_type @formatted_type end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/pcrd/schema/column.rb', line 6 def name @name end |
#nullable ⇒ Object (readonly)
Returns the value of attribute nullable.
6 7 8 |
# File 'lib/pcrd/schema/column.rb', line 6 def nullable @nullable end |
#type_name ⇒ Object (readonly)
Returns the value of attribute type_name.
6 7 8 |
# File 'lib/pcrd/schema/column.rb', line 6 def type_name @type_name end |
Instance Method Details
#==(other) ⇒ Object
50 51 52 |
# File 'lib/pcrd/schema/column.rb', line 50 def ==(other) other.is_a?(Column) && name == other.name && type_name == other.type_name end |
#display_alignment ⇒ Object
46 47 48 |
# File 'lib/pcrd/schema/column.rb', line 46 def display_alignment "#{alignment}B" end |
#display_size ⇒ Object
42 43 44 |
# File 'lib/pcrd/schema/column.rb', line 42 def display_size fixed_size ? fixed_size.to_s : "variable" end |
#display_type ⇒ Object
Human-readable type string, with common verbose PG names shortened.
32 33 34 35 36 37 38 39 40 |
# File 'lib/pcrd/schema/column.rb', line 32 def display_type formatted_type .sub("character varying", "varchar") .sub("character(", "char(") .sub("timestamp without time zone", "timestamp") .sub("timestamp with time zone", "timestamptz") .sub("time without time zone", "time") .sub("time with time zone", "timetz") end |
#fixed? ⇒ Boolean
27 28 29 |
# File 'lib/pcrd/schema/column.rb', line 27 def fixed? !variable? end |
#inspect ⇒ Object
54 55 56 |
# File 'lib/pcrd/schema/column.rb', line 54 def inspect "#<Pcrd::Schema::Column #{name}:#{display_type} align=#{alignment} size=#{display_size}>" end |
#variable? ⇒ Boolean
23 24 25 |
# File 'lib/pcrd/schema/column.rb', line 23 def variable? fixed_size.nil? end |