Sha256: 2978aa9e3024e2847b6a24537906960c24db18f1a4d8b544b402ff2b4fba979e
Contents?: true
Size: 1.21 KB
Versions: 50
Compression:
Stored size: 1.21 KB
Contents
module Appfuel module Repository class OrderExpr < Expr def self.build(data) return [data] if data.instance_of?(self) data = [data] if data.is_a?(String) unless data.respond_to?(:each) fail "order must be a string or implement :each" end results = [] data.each do |item| item = parse_order_string(item) if item.is_a?(String) if item.instance_of?(self) results << item next end if !item.is_a?(Hash) fail "order array must be a list of strings or hashes" end domain_attr, dir = item.first results << self.new(domain_attr, dir) end results end def initialize(domain_attr, op = nil) op ||= 'asc' super(domain_attr, op, nil) @op = @op.downcase unless ['asc', 'desc'].include?(@op) fail "order direction must be either asc or desc" end end def to_s "#{attr_list.join('.')} #{op}" end private def self.parse_order_string(str) str, dir = str.split(' ') dir = 'asc' if dir.nil? {str => dir.downcase} end end end end
Version data entries
50 entries across 50 versions & 1 rubygems