Sha256: b2023120e1166532597395293183657ddb2eac16888bbb762f87084e59943b45

Contents?: true

Size: 927 Bytes

Versions: 1

Compression:

Stored size: 927 Bytes

Contents

class Importer
  
  class Error
     
    attr_reader :row, :text
    
    def initialize(context, text)
      if context.is_a?(Importer::Row)
        @row = context
      end
      @text = text.to_s
    end
    
    def summary
      summary = ''
      if @row
        summary += "#{@row}: "
      end
      summary + @text
    end

    def to_s
      summary
    end
    
    # Returns the level at which this error occurred, one of
    # :row, :importer
    def level
      return :row if @row
      return :importer
    end
    
    def row_level?
      level == :row
    end
    
    def importer_level?
      level == :importer
    end

    # Returns true if this error is for the given context, where
    # context can be a Row, Sheet or Importer instance.
    def for_context?(context)
      case context
      when Row
        return @row == context
      else
        return true
      end  
    end
    
  end
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
iron-import-0.7.0 lib/iron/import/error.rb