Class: Administrate::Field::CSV

Inherits:
Base
  • Object
show all
Defined in:
lib/administrate/field/csv.rb

Defined Under Namespace

Classes: Engine

Instance Method Summary collapse

Instance Method Details

#blank_signObject



37
38
39
# File 'lib/administrate/field/csv.rb', line 37

def blank_sign
  options[:blank_sign] || '-'
end

#has_headers?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/administrate/field/csv.rb', line 29

def has_headers?
  options[:headers] == true
end

#headersObject



22
23
24
25
26
27
# File 'lib/administrate/field/csv.rb', line 22

def headers
  return [] unless has_headers?

  rewind
  @headers ||= transform.first&.headers || []
end

#rewindObject



16
17
18
19
20
# File 'lib/administrate/field/csv.rb', line 16

def rewind
  return nil if data.blank?

  transform.rewind
end

#to_partial_path(partial = page) ⇒ Object



33
34
35
# File 'lib/administrate/field/csv.rb', line 33

def to_partial_path(partial = page)
  "/fields/csv/#{partial}"
end

#transformObject



10
11
12
13
14
# File 'lib/administrate/field/csv.rb', line 10

def transform
  return nil if data.blank?

  @transform ||= ::CSV.new(data, **csv_args)
end

#truncateObject



41
42
43
# File 'lib/administrate/field/csv.rb', line 41

def truncate
  data.to_s.truncate(truncation_length)
end