class MARC::Spec::Queries::Position

Attributes

position[R]

Attributes

Public Class Methods

new(position) click to toggle source
# File lib/marc/spec/queries/position.rb, line 14
def initialize(position)
  @position = int_or_nil(position)
end

Public Instance Methods

select_from(seq) click to toggle source

@overload select_from(seq)

Selects the value at the specified position and returns it as a
single-element array, for compatibility with AlNumRange
@param seq [Array] the input array
@return [Array] a single-element array containing the result, or
  an empty array if the index is out of bounds

@overload select_from(seq)

Selects the character at the specified position
@param seq [String] the input array
@return [String, nil] a single-element array, or nil if the index
  is out of bounds
# File lib/marc/spec/queries/position.rb, line 32
def select_from(seq)
  # we use raw_result[-1] instead of raw_result.last b/c seq might be a string
  raw_result = seq[position.nil? ? -1 : position]
  seq.is_a?(String) ? wrap_string_result(raw_result) : wrap_array_result(raw_result)
end
to_s() click to toggle source

Object overrides

# File lib/marc/spec/queries/position.rb, line 41
def to_s
  (position || '#').to_s
end

Protected Instance Methods

equality_attrs() click to toggle source

Part

# File lib/marc/spec/queries/position.rb, line 53
def equality_attrs
  [:position]
end