Class: PgDice::Table
Overview
Object to represent a table’s configuration in the context of PgDice.
Instance Attribute Summary collapse
-
#column_name ⇒ Object
Returns the value of attribute column_name.
-
#future ⇒ Object
Returns the value of attribute future.
-
#past ⇒ Object
Returns the value of attribute past.
-
#period ⇒ Object
Returns the value of attribute period.
-
#schema ⇒ Object
Returns the value of attribute schema.
-
#table_name ⇒ Object
readonly
Returns the value of attribute table_name.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object
- #full_name ⇒ Object
-
#initialize(table_name:, past: 90, future: 7, column_name: 'created_at', period: 'day', schema: 'public') ⇒ Table
constructor
A new instance of Table.
- #name ⇒ Object
-
#size ⇒ Object
Get expected size of this configured table (past + present + future table counts).
- #smash(override_parameters) ⇒ Object
- #to_h ⇒ Object
- #to_s ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize(table_name:, past: 90, future: 7, column_name: 'created_at', period: 'day', schema: 'public') ⇒ Table
Returns a new instance of Table.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/pgdice/table.rb', line 10 def initialize(table_name:, past: 90, future: 7, column_name: 'created_at', period: 'day', schema: 'public') raise ArgumentError, 'table_name must be a string' unless table_name.is_a?(String) @table_name = table_name @past = past @future = future @column_name = column_name @period = period @schema = schema end |
Instance Attribute Details
#column_name ⇒ Object
Returns the value of attribute column_name.
8 9 10 |
# File 'lib/pgdice/table.rb', line 8 def column_name @column_name end |
#future ⇒ Object
Returns the value of attribute future.
8 9 10 |
# File 'lib/pgdice/table.rb', line 8 def future @future end |
#past ⇒ Object
Returns the value of attribute past.
8 9 10 |
# File 'lib/pgdice/table.rb', line 8 def past @past end |
#period ⇒ Object
Returns the value of attribute period.
8 9 10 |
# File 'lib/pgdice/table.rb', line 8 def period @period end |
#schema ⇒ Object
Returns the value of attribute schema.
8 9 10 |
# File 'lib/pgdice/table.rb', line 8 def schema @schema end |
#table_name ⇒ Object (readonly)
Returns the value of attribute table_name.
7 8 9 |
# File 'lib/pgdice/table.rb', line 7 def table_name @table_name end |
Class Method Details
Instance Method Details
#<=>(other) ⇒ Object
63 64 65 |
# File 'lib/pgdice/table.rb', line 63 def <=>(other) table_name <=> other.table_name end |
#==(other) ⇒ Object
59 60 61 |
# File 'lib/pgdice/table.rb', line 59 def ==(other) to_h == other.to_h end |
#full_name ⇒ Object
38 39 40 |
# File 'lib/pgdice/table.rb', line 38 def full_name "#{schema}.#{name}" end |
#name ⇒ Object
34 35 36 |
# File 'lib/pgdice/table.rb', line 34 def name table_name end |
#size ⇒ Object
Get expected size of this configured table (past + present + future table counts)
68 69 70 |
# File 'lib/pgdice/table.rb', line 68 def size past + future + 1 end |
#smash(override_parameters) ⇒ Object
55 56 57 |
# File 'lib/pgdice/table.rb', line 55 def smash(override_parameters) to_h.merge!(override_parameters) end |
#to_h ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/pgdice/table.rb', line 42 def to_h { table_name: table_name, past: past, future: future, column_name: column_name, period: period, schema: schema } end |
#to_s ⇒ Object
51 52 53 |
# File 'lib/pgdice/table.rb', line 51 def to_s "#{schema}.#{name}: <past: #{past}, future: #{future}, column_name: #{column_name}, period: #{period}>" end |
#validate! ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/pgdice/table.rb', line 21 def validate! check_type(:past, Integer) check_type(:future, Integer) check_type(:column_name, String) check_type(:period, String) check_type(:schema, String) unless PgDice::SUPPORTED_PERIODS.include?(period) raise ArgumentError, "Period must be one of: #{PgDice::SUPPORTED_PERIODS.keys}. Value: #{period} is not valid." end true end |