Sha256: d5e8cee40da40fa659ada6df63b0aa350ba10f5f63d525ded3004a831d794bb4

Contents?: true

Size: 700 Bytes

Versions: 1

Compression:

Stored size: 700 Bytes

Contents

class Range

  # Nudge range values
  #
  #   (1..5).nudge           #=> 2..6
  #   (1..5).nudge(2)        #=> 3..7
  #   (1..5).nudge(-2)       #=> -1..3
  #   (1..5).nudge(min: 1)   #=> 2..5
  #   (1..5).nudge(max: 1)   #=> 1..6
  #
  # CREDIT: Codeindulgence

  def nudge(options_or_number = 1)
    if options_or_number.instance_of? Fixnum
      {:min => options_or_number, :max => options_or_number}
      min = options_or_number
      max = options_or_number
    else
      min = options_or_number[:min].to_i
      max = options_or_number[:max].to_i
    end

    if exclude_end?
      (self.min + min)...((self.max + 1) + max)
    else
      (self.min + min)..(self.max + max)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
facets-3.1.0 lib/core/facets/range/nudge.rb