Class: SpreadsheetBuilder::StringColumn

Inherits:
Object
  • Object
show all
Defined in:
backend/app/model/spreadsheet_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(jsonmodel, name, opts = {}) ⇒ StringColumn

Returns a new instance of StringColumn.



29
30
31
32
33
34
35
36
37
38
39
40
# File 'backend/app/model/spreadsheet_builder.rb', line 29

def initialize(jsonmodel, name, opts = {})
  @jsonmodel = jsonmodel
  @name = name
  @header_label = opts.fetch(:header_label, nil)
  @column = opts.fetch(:column, name).intern
  @width = opts.fetch(:width, nil)
  @locked = opts.fetch(:locked, false)
  @property_name = opts.fetch(:property_name, jsonmodel).to_s
  @i18n = opts.fetch(:i18n, I18n.t("#{@jsonmodel}.#{@name}", :default => @name))
  @i18n_proc = opts.fetch(:i18n_proc, nil)
  @path_proc = opts.fetch(:path_proc, nil)
end

Instance Attribute Details

#columnObject

Returns the value of attribute column



27
28
29
# File 'backend/app/model/spreadsheet_builder.rb', line 27

def column
  @column
end

#indexObject

Returns the value of attribute index



27
28
29
# File 'backend/app/model/spreadsheet_builder.rb', line 27

def index
  @index
end

#jsonmodelObject

Returns the value of attribute jsonmodel



27
28
29
# File 'backend/app/model/spreadsheet_builder.rb', line 27

def jsonmodel
  @jsonmodel
end

#lockedObject

Returns the value of attribute locked



27
28
29
# File 'backend/app/model/spreadsheet_builder.rb', line 27

def locked
  @locked
end

#nameObject

Returns the value of attribute name



27
28
29
# File 'backend/app/model/spreadsheet_builder.rb', line 27

def name
  @name
end

#property_nameObject

Returns the value of attribute property_name



27
28
29
# File 'backend/app/model/spreadsheet_builder.rb', line 27

def property_name
  @property_name
end

#widthObject

Returns the value of attribute width



27
28
29
# File 'backend/app/model/spreadsheet_builder.rb', line 27

def width
  @width
end

Instance Method Details

#header_labelObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'backend/app/model/spreadsheet_builder.rb', line 46

def header_label
  if @header_label.nil?
    if @i18n_proc
      @index = 0 if @index.nil?
      @header_label = @i18n_proc.call(self)
    else
      if @index.nil?
        @header_label = @i18n
      else
        @header_label = "#{I18n.t("#{jsonmodel}._singular")} #{index + 1} - #{@i18n}"
      end
    end
  end
  @header_label
end

#pathObject



62
63
64
65
66
67
68
69
70
71
72
# File 'backend/app/model/spreadsheet_builder.rb', line 62

def path
  if @path_proc
    return @path_proc.call(self)
  end

  if jsonmodel == :archival_object
    name.to_s
  else
    [@property_name, index, name].join('/')
  end
end

#sanitise_incoming_value(value) ⇒ Object



74
75
76
77
78
# File 'backend/app/model/spreadsheet_builder.rb', line 74

def sanitise_incoming_value(value)
  return nil if value.nil?

  value.to_s.strip
end

#value_for(column_value) ⇒ Object



42
43
44
# File 'backend/app/model/spreadsheet_builder.rb', line 42

def value_for(column_value)
  column_value
end