module MARC::Spec::Queries::Part

Supermodule of partial query

Public Instance Methods

==(other)
Alias for: eql?
eql?(other) click to toggle source
# File lib/marc/spec/queries/part.rb, line 14
def eql?(other)
  return false unless other.class == self.class

  equality_attrs.all? do |attr|
    send(attr) == other.send(attr)
  end
end
Also aliased as: ==
hash() click to toggle source
# File lib/marc/spec/queries/part.rb, line 24
def hash
  @hash_val ||= begin
    equality_vals = equality_attrs.map { |attr| send(attr) }
    equality_vals.inject(31 + self.class.hash) { |r, v| 31 * r + v.hash }
  end
end
inspect() click to toggle source

Object overrides

# File lib/marc/spec/queries/part.rb, line 10
def inspect
  "#{class_name(self)}<#{to_s_inspect}>"
end

Protected Instance Methods

ensure_type(v, type, allow_nil: false) click to toggle source
# File lib/marc/spec/queries/part.rb, line 40
def ensure_type(v, type, allow_nil: false)
  return if allow_nil && v.nil?
  return v if v.is_a?(type)

  raise ArgumentError, "Not a #{class_name(type)}: #{v.inspect}"
end
int_or_nil(v) click to toggle source
# File lib/marc/spec/queries/part.rb, line 47
def int_or_nil(v)
  return nil if v.nil? || v == '#'

  Integer(v)
end
to_s_inspect() click to toggle source

Protected methods

# File lib/marc/spec/queries/part.rb, line 36
def to_s_inspect
  to_s
end

Private Instance Methods

class_name(t) click to toggle source
# File lib/marc/spec/queries/part.rb, line 55
def class_name(t)
  return class_name(t.class) unless t.is_a?(Class) || t.is_a?(Module)

  t.name.sub(/^.*::/, '')
end