Class: CustomSort::MagicNew

Inherits:
Object
  • Object
show all
Defined in:
lib/custom_sort/magic_new.rb

Direct Known Subclasses

Enumerable, Relation

Defined Under Namespace

Classes: Enumerable, Relation

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query_name:, **options) ⇒ MagicNew

Returns a new instance of MagicNew.



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/custom_sort/magic_new.rb', line 7

def initialize(query_name:, **options)
    @query_name = query_name
    @options = options

    @recent = options[:recent] == false ? false : true
    @recency_key = options[:recency_key] ? options[:recency_key].to_i : 2
    @label = options[:label] ? options[:label] : nil
    @label = @label.nil? ? CustomSort::LABELS[0].to_s : @label

    @sort_order = options[:sort_order] ? (["asc","desc"].include?(options[:sort_order].downcase) ? options[:sort_order] : "desc") : "desc"
    
end

Instance Attribute Details

#labelObject

Returns the value of attribute label.



5
6
7
# File 'lib/custom_sort/magic_new.rb', line 5

def label
  @label
end

#optionsObject

Returns the value of attribute options.



5
6
7
# File 'lib/custom_sort/magic_new.rb', line 5

def options
  @options
end

#query_nameObject

Returns the value of attribute query_name.



5
6
7
# File 'lib/custom_sort/magic_new.rb', line 5

def query_name
  @query_name
end

#recency_keyObject

Returns the value of attribute recency_key.



5
6
7
# File 'lib/custom_sort/magic_new.rb', line 5

def recency_key
  @recency_key
end

#recentObject

Returns the value of attribute recent.



5
6
7
# File 'lib/custom_sort/magic_new.rb', line 5

def recent
  @recent
end

#sort_orderObject

Returns the value of attribute sort_order.



5
6
7
# File 'lib/custom_sort/magic_new.rb', line 5

def sort_order
  @sort_order
end

Class Method Details

.validate_period(period, permit) ⇒ Object

Raises:

  • (ArgumentError)


20
21
22
23
# File 'lib/custom_sort/magic_new.rb', line 20

def self.validate_period(period, permit)
  permitted_periods = ((permit || CustomSort::FIELDS).map(&:to_sym) & CustomSort::FIELDS).map(&:to_s)
  raise ArgumentError, "Unpermitted period" unless permitted_periods.include?(period.to_s)
end