Sha256: dd84cc65b5d7e1f60b2f96089fe79f18af29d66a3cc7d7bd8c9ea68b24e01c18

Contents?: true

Size: 737 Bytes

Versions: 1

Compression:

Stored size: 737 Bytes

Contents

# encoding: utf-8

class EsrFile < ActiveRecord::Base
  # Access restrictions
  attr_accessible :file, :remarks

  # Default sorting
  default_scope order('created_at DESC')

  # File upload
  mount_uploader :file, EsrFileUploader

  has_many :esr_records, :dependent => :destroy
  
  # String
  def to_s(format = :default)
    case format
    when :long
      s = ''
      esr_records.each {|record|
        s += record.to_s + "\n"
      }
      s
    else
      "#{updated_at.strftime('%d.%m.%Y')}: #{file_identifier}"
    end
  end

  after_save :create_records

  private
  def create_records
    File.new(file.current_path).each {|line|
      self.esr_records << EsrRecord.new.parse(line) unless line[0..2] == '999'
    }
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vesr-0.12.7 app/models/esr_file.rb