Class: AnixeCsv::Formatter::Field
- Inherits:
-
Object
- Object
- AnixeCsv::Formatter::Field
- Defined in:
- lib/anixe_csv/formatter.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
Returns the value of attribute block.
-
#default ⇒ Object
Returns the value of attribute default.
-
#name ⇒ Object
Returns the value of attribute name.
-
#regexp ⇒ Object
Returns the value of attribute regexp.
Instance Method Summary collapse
-
#initialize(*args) ⇒ Field
constructor
A new instance of Field.
- #prepare_value(s) ⇒ Object
- #to_s(s = nil) ⇒ Object
- #value ⇒ Object
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
#block ⇒ Object
Returns the value of attribute block.
166 167 168 |
# File 'lib/anixe_csv/formatter.rb', line 166 def block @block end |
#default ⇒ Object
Returns the value of attribute default.
166 167 168 |
# File 'lib/anixe_csv/formatter.rb', line 166 def default @default end |
#name ⇒ Object
Returns the value of attribute name.
166 167 168 |
# File 'lib/anixe_csv/formatter.rb', line 166 def name @name end |
#regexp ⇒ Object
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 |
#value ⇒ Object
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 |