class SimpleJsonapi::Parameters::SortFieldSpec

Represents a single field (and direction) in a {SortSpec}. @!attribute [rw] field

@return Symbol

@!attribute [rw] dir

@return [:asc,:desc]

Attributes

dir[RW]
field[RW]

Public Class Methods

new(spec) click to toggle source

@param spec [String]

# File lib/simple_jsonapi/parameters/sort_spec.rb, line 72
def initialize(spec)
  if spec =~ /\A(-?)(\w+)\Z/
    self.field = $2.to_sym
    self.dir = ($1 == '-' ? :desc : :asc)
  else
    raise ArgumentError, "field spec must match 'field' or '-field'"
  end
end

Public Instance Methods

==(other) click to toggle source
# File lib/simple_jsonapi/parameters/sort_spec.rb, line 93
def ==(other)
  other.respond_to?(:field) && other.respond_to?(:dir) && [field, dir] == [other.field, other.dir]
end
Also aliased as: eql?
asc?() click to toggle source
# File lib/simple_jsonapi/parameters/sort_spec.rb, line 81
def asc?
  dir == :asc
end
desc?() click to toggle source
# File lib/simple_jsonapi/parameters/sort_spec.rb, line 85
def desc?
  dir == :desc
end
dup() click to toggle source
# File lib/simple_jsonapi/parameters/sort_spec.rb, line 89
def dup
  SortFieldSpec.new(to_s)
end
eql?(other)
Alias for: ==
hash() click to toggle source
# File lib/simple_jsonapi/parameters/sort_spec.rb, line 98
def hash
  [field, dir].hash
end
inspect()
Alias for: to_s
to_s() click to toggle source
# File lib/simple_jsonapi/parameters/sort_spec.rb, line 102
def to_s
  "#{'-' if desc?}#{field}"
end
Also aliased as: inspect