Class: AnixeCsv::Formatter::Field

Inherits:
Object
  • Object
show all
Defined in:
lib/anixe_csv/formatter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Field

Returns a new instance of Field.



172
173
174
175
176
# File 'lib/anixe_csv/formatter.rb', line 172

def initialize(*args)
  @name = args[0]
  @default = args[1] unless args[1].nil?
  @opts = args[2] || {}
end

Instance Attribute Details

#blockObject

Returns the value of attribute block.



166
167
168
# File 'lib/anixe_csv/formatter.rb', line 166

def block
  @block
end

#defaultObject

Returns the value of attribute default.



166
167
168
# File 'lib/anixe_csv/formatter.rb', line 166

def default
  @default
end

#nameObject

Returns the value of attribute name.



166
167
168
# File 'lib/anixe_csv/formatter.rb', line 166

def name
  @name
end

#regexpObject

Returns the value of attribute regexp.



166
167
168
# File 'lib/anixe_csv/formatter.rb', line 166

def regexp
  @regexp
end

Instance Method Details

#prepare_value(s) ⇒ Object



186
187
188
189
190
191
192
# File 'lib/anixe_csv/formatter.rb', line 186

def prepare_value(s)
  unless block.nil?
    block.call(s, self)
  else
    s
  end
end

#to_s(s = nil) ⇒ Object



178
179
180
181
182
183
184
# File 'lib/anixe_csv/formatter.rb', line 178

def to_s(s=nil)
  return prepare_value(s) if @opts.empty?

  pad = @opts[:pad] || ' '
  return prepare_value(s).ljust(@opts[:ljust], pad) if @opts[:ljust]
  return prepare_value(s).rjust(@opts[:rjust], pad) if @opts[:rjust]
end

#valueObject



168
169
170
# File 'lib/anixe_csv/formatter.rb', line 168

def value
  raise "The use of value is deprecated, use the instance methods instead"
end