Class: TableWarnings::Warning::Size

Inherits:
TableWarnings::Warning show all
Defined in:
lib/table_warnings/warning/size.rb

Instance Attribute Summary collapse

Attributes inherited from TableWarnings::Warning

#table

Instance Method Summary collapse

Methods inherited from TableWarnings::Warning

#eql?, #hash, #initialize, #to_hash

Constructor Details

This class inherits a constructor from TableWarnings::Warning

Instance Attribute Details

#approximate_sizeObject (readonly)

Returns the value of attribute approximate_size.



4
5
6
# File 'lib/table_warnings/warning/size.rb', line 4

def approximate_size
  @approximate_size
end

Instance Method Details

#allowed_rangeObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/table_warnings/warning/size.rb', line 6

def allowed_range
  case approximate_size
  when :few
    1..10
  when :dozens, :tens
    10..100
  when :hundreds
    100..1_000
  when :thousands
    1_000..99_000
  when :hundreds_of_thousands
    100_000..1_000_000
  when :millions
    1_000_000..1_000_000_000
  when Range
    approximate_size
  when Numeric
    approximate_size..approximate_size
  end
end

#messagesObject



27
28
29
30
31
# File 'lib/table_warnings/warning/size.rb', line 27

def messages
  unless allowed_range.include? table.count
    "Table is not of expected size (expected: #{allowed_range.to_s}, actual: #{table.count})"
  end
end