Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sort-by-alphabet

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sort-by-alphabet

  • 0.2.6
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

This library implements alphabetical sorting according to given alphabet scheme. Currently, only Czech alphabet is included, but it is super-easy to create a new one.

h1. Setup

Install the gem:

bc. gem install sort-by-alphabet

Or require it into Rails:

bc. gem require "sort-by-alphabet"

h1. Requirements

Support of @mb_chars@, i.e. ActiveSupport in practice.

h1. Usage

Classical sort puts accented chars after normal:

bc. %w{nazdar ahoj čau}.sort # => %w{ahoj nazdar čau}

@sort_by_alphabet@ does a better job:

bc. %w{nazdar ahoj čau}.sort_by_alphabet(CzechAlphabet) # => %w{ahoj čau nazdar}

@sort_by_alphabet@ can take a block which acts similarly as that in @sort_by@:

bc. Something.all.sort_by_alphabet(CzechAlphabet) {|o| o.title}

You can also make a class alphabetically comparable, enabling sorting:

bc.. class Something comparable_by_alphabet(CzechAlphabet) end

a = Something.new b = Something.new c = Something.new

the following comparisons will be using to_s and lexical order given by Czech alphabet

a <=> b

[a, b, c].sort

p. or use a block, e.g. for case insensitivity:

bc. class SomethingElse comparable_by_alphabet(CzechAlphabet) {|obj| obj.mb_chars.downcase} end

FAQs

Package last updated on 30 Aug 2010

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc