Class: Importer::Error

Inherits:
Object
  • Object
show all
Defined in:
lib/iron/import/error.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context, text) ⇒ Error

Returns a new instance of Error.



7
8
9
10
11
12
13
14
15
# File 'lib/iron/import/error.rb', line 7

def initialize(context, text)
  if context.is_a?(Importer::Sheet)
    @sheet = context
  elsif context.is_a?(Importer::Row)
    @row = context
    @sheet = context.sheet
  end
  @text = text.to_s
end

Instance Attribute Details

#rowObject (readonly)

Returns the value of attribute row.



5
6
7
# File 'lib/iron/import/error.rb', line 5

def row
  @row
end

#sheetObject (readonly)

Returns the value of attribute sheet.



5
6
7
# File 'lib/iron/import/error.rb', line 5

def sheet
  @sheet
end

#textObject (readonly)

Returns the value of attribute text.



5
6
7
# File 'lib/iron/import/error.rb', line 5

def text
  @text
end

Instance Method Details

#for_context?(context) ⇒ Boolean

Returns true if this error is for the given context, where context can be a Row, Sheet or Importer instance.

Returns:

  • (Boolean)


53
54
55
56
57
58
59
60
61
62
# File 'lib/iron/import/error.rb', line 53

def for_context?(context)
  case context
  when Row
    return @row == context
  when Sheet
    return @sheet == context
  else
    return true
  end  
end

#importer_level?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/iron/import/error.rb', line 47

def importer_level?
  level == :importer
end

#levelObject

Returns the level at which this error occurred, one of :row, :sheet, :importer



33
34
35
36
37
# File 'lib/iron/import/error.rb', line 33

def level
  return :row if @row
  return :sheet if @sheet
  return :importer
end

#row_level?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/iron/import/error.rb', line 39

def row_level?
  level == :row
end

#sheet_level?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/iron/import/error.rb', line 43

def sheet_level?
  level == :sheet
end

#summaryObject



17
18
19
20
21
22
23
24
25
# File 'lib/iron/import/error.rb', line 17

def summary
  summary = ''
  if @row
    summary += "#{@sheet} #{@row}: "
  elsif @sheet
    summary += "#{@sheet}: "
  end
  summary + @text
end

#to_sObject



27
28
29
# File 'lib/iron/import/error.rb', line 27

def to_s
  summary
end