Class: Kiba::Extend::Transforms::Sort::ByFieldValue
- Inherits:
-
Object
- Object
- Kiba::Extend::Transforms::Sort::ByFieldValue
- Defined in:
- lib/kiba/extend/transforms/sort/by_field_value.rb
Overview
Returns all rows, sorted by the values of the given field.
Sort modes
:smart: Values consisting only of digits are converted to Integers for sort. Values consisting only of digits and a single “.” are converted to Floats. Everything else is treated as a String.
:string: All values treated as Strings
Instance Method Summary collapse
-
#close ⇒ Object
-
#initialize(field:, blanks: :last, delim: nil, mode: :smart, order: :asc) ⇒ ByFieldValue
constructor
A new instance of ByFieldValue.
-
#process(row) ⇒ Object
Constructor Details
#initialize(field:, blanks: :last, delim: nil, mode: :smart, order: :asc) ⇒ ByFieldValue
Returns a new instance of ByFieldValue.
157 158 159 160 161 162 163 164 165 |
# File 'lib/kiba/extend/transforms/sort/by_field_value.rb', line 157 def initialize(field:, blanks: :last, delim: nil, mode: :smart, order: :asc) @field = field @blanks = blanks @delim = delim @mode = mode @order = order @rows = {string: [], numeric: [], blank: []} end |
Instance Method Details
#close ⇒ Object
179 180 181 182 183 |
# File 'lib/kiba/extend/transforms/sort/by_field_value.rb', line 179 def close rows[:blank].each { |row| yield row } if blanks == :first sorted.each { |entry| yield entry[1] } rows[:blank].each { |row| yield row } if blanks == :last end |
#process(row) ⇒ Object
168 169 170 171 172 173 174 175 176 177 |
# File 'lib/kiba/extend/transforms/sort/by_field_value.rb', line 168 def process(row) if row.key?(field) val = row[field] val.blank? ? rows[:blank] << row : sortable(row, val) else rows[:blank] << row end nil end |