Class: AttributeStats::TableData

Inherits:
Object
  • Object
show all
Defined in:
lib/entities/table_data.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model) ⇒ TableData

Returns a new instance of TableData.



4
5
6
7
8
9
10
11
12
# File 'lib/entities/table_data.rb', line 4

def initialize(model)
  @model        = model
  @name         = model.name
  @table_name   = model.table_name
  @attributes   = []
  @dormant      = false
  @count        = 0
  @column_names = model.columns.map(&:name)
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



3
4
5
# File 'lib/entities/table_data.rb', line 3

def attributes
  @attributes
end

#countObject (readonly)

Returns the value of attribute count.



3
4
5
# File 'lib/entities/table_data.rb', line 3

def count
  @count
end

#last_updatedObject (readonly)

Returns the value of attribute last_updated.



3
4
5
# File 'lib/entities/table_data.rb', line 3

def last_updated
  @last_updated
end

#modelObject (readonly)

Returns the value of attribute model.



3
4
5
# File 'lib/entities/table_data.rb', line 3

def model
  @model
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/entities/table_data.rb', line 3

def name
  @name
end

#table_nameObject (readonly)

Returns the value of attribute table_name.



3
4
5
# File 'lib/entities/table_data.rb', line 3

def table_name
  @table_name
end

Instance Method Details

#attribute_for(attribute_name) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/entities/table_data.rb', line 32

def attribute_for(attribute_name)
  unless attribute = attributes.detect{|a| a.name == attribute_name }
    attribute = AttributeInfo.new(attribute_name)
    @attributes << attribute
  end
  attribute
end

#column_namesObject



14
15
16
# File 'lib/entities/table_data.rb', line 14

def column_names
  @column_names
end

#dormant?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/entities/table_data.rb', line 24

def dormant?
  @dormant
end

#make_dormant(last_updated) ⇒ Object



18
19
20
21
22
# File 'lib/entities/table_data.rb', line 18

def make_dormant(last_updated)
  @dormant = true
  last_updated  = last_updated.to_datetime unless last_updated.nil?
  @last_updated = last_updated
end

#set_count(total_record_count) ⇒ Object



28
29
30
# File 'lib/entities/table_data.rb', line 28

def set_count(total_record_count)
  @count = total_record_count
end

#unused_attributesObject



40
41
42
43
44
45
46
47
48
# File 'lib/entities/table_data.rb', line 40

def unused_attributes
  @unused_attributes ||= begin
    attrs = []
    @attributes.each do |attribute|
      attrs << attribute.name if attribute.empty?
    end
    attrs
  end
end