• This repository has been archived on 04/Mar/2018
  • Stars
    star
    516
  • Rank 85,726 (Top 2 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 11 years ago
  • Updated almost 11 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Human Expressions, a human way to define regular expressions

Hexpress

  • Gem Version
  • Code Climate
  • Build Status
  • Dependency Status
  • Coverage Status

The hexpress gem is another take at the concept of "Verbal Hexpressions" in Ruby.

Using

require "hexpress"

pattern = Hexpress.new

pattern = Hexpress.new.
  start("http").
  maybe("s").
  with("://").
  maybe { words.with(".") }.
  find { matching { [word, "-"] }.multiple }.
  has(".").
  either("com", "org").
  maybe("/").
  ending

After requiring hexpress you'll have access to the Hexpress class, which allows you to chain methods to build up a regex pattern.

You can see this pattern by calling either Hexpress#to_s or Hexpress#to_r:

pattern.to_s #=> "^http(?:s)?://(?:(?:\\w)+\\.)?([\\w\\-]+)\\.(?:com|org)(?:/)?$"
pattern.to_r #=> /^http(?:s)?:\/\/(?:(?:\w)+\.)?([\w\-]+)\.(?:com|org)(?:\/)?$/

You can also get access to a global method by doing the following (automatically done in any rails application):

require_relative "hexpress/main"

hexp.start("http").maybe("s")

hexp do
  start("http")
  maybe("s")
end

In addition we've bundled an extra set of helpers for specific use cases like the web:

require "hexpress"
require "hexpress/web"

pattern = hexp.http.domain("amazon").tld("com")
pattern = hexp.ftp # ...

You can even do advanced composure of multiple patterns:

protocol = exp.start("http").maybe("s").with("://")
tld = exp.then(".").either("org", "com", "net")
link = exp.has(protocol).find { words }.including(tld)

It's also entirely feasible to compound two or more patterns together:

protocol = exp.start("http").maybe("s").with("://")
domain = exp.find { words }
tld = exp.then(".").either("org", "com", "net")
link =  protocol + domain + tld

Hexpressions are very flexible.

Installing

Add this line to your application's Gemfile:

gem "hexpress", "~> 1.0"

And then execute:

$ bundle

Or install it yourself as:

$ gem install hexpress

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Licensing

Copyright (c) 2013 Kurtis Rainbolt-Greene

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

More Repositories

1

termnote

Keynotes in your flippin' TERMINAL!
Ruby
275
star
2

time-lord

time-lord is a ruby gem that adds extra functionality to the time class.
Ruby
158
star
3

learn-you-the-ruby-for-awesome-power

You want to learn Ruby?! Then lets learn Ruby! ARRGHHHH. Based off Learn Python The Hard Way and Learn You A Haskell.
Ruby
69
star
4

snabbdom-helpers

A set of functions for the snabbdom virtualdom library
JavaScript
17
star
5

paper_trail-background.rb

Process Papertrail versioning in the background
Ruby
16
star
6

email_spy

Opens up app-sent emails in your browser
Ruby
14
star
7

unction.js

[DEPRECATED] A set of type annotated FP functions that enforce currying and composability
JavaScript
13
star
8

smart_params.rb

This gem gives developers an easy to understand and easy to maintain schema for request parameters.
Ruby
12
star
9

authn

Making Authentication Simple & Fast
Ruby
10
star
10

jsonapi-realizer.rb

Turn JSON:API requests into real records
Ruby
9
star
11

astruct.gem

An alternative to ostruct
Ruby
7
star
12

architecture.gem

architecture.gem is a filesystem library for easy scaffold generator creation
Ruby
7
star
13

mage

It's the magically easy way to get system details about your platform
Ruby
6
star
14

abstraction.js

A way to model data
JavaScript
6
star
15

tardis.gem

The tools of time & space
Ruby
6
star
16

action_operation.rb

A business logic processing service
Ruby
4
star
17

jsonapi-home.rb

A json-home implementation in JSON:API
Ruby
4
star
18

authn-rails

The Rails integration for the AuthN authentication library
Ruby
4
star
19

validus.js

A set of validation logic that results in error information
JavaScript
4
star
20

library.io

An Io library manager
Io
3
star
21

rorth

Forth On Ruby
Ruby
3
star
22

instahub

Easier to read Github READMEs
Ruby
3
star
23

blank-gem

Ruby
3
star
24

bard

The Dungeon Master Team HackDat entry
Ruby
3
star
25

intrinsic

a library for complex data storage and object modeling
Ruby
3
star
26

shogun.gem

A HTTP API library core
Ruby
3
star
27

recordType.js

An implementation of the Record datatype
JavaScript
2
star
28

scrawl.gem

Simple to parse strings for logging or something
Ruby
2
star
29

faux

A Factory-style fake data generator
Ruby
2
star
30

distribute

A distribution tool for binaries and libraries
Ruby
2
star
31

hsdk.js

A HATEOAS HTTP client that generates SDKs based on a specific endpoint
JavaScript
2
star
32

nolaonrails

The NOLA on Rails application
Ruby
2
star
33

metrix

JavaScript
2
star
34

whiskey

A specialized server for text based RPGs
Ruby
2
star
35

baldurs-mouth

A cute implementation of the Baldur's Gate 3 dialog system
Elixir
2
star
36

rack-authentication_bearer.rb

A middleware for grabbing the Authentication or Authorization header of the request, for Bearer tokens
Ruby
2
star
37

financ.io

A financial tracking application
Ruby
1
star
38

elephas

A tiny implementation of the spec required to interop with mastodon
Elixir
1
star
39

jsonapi-materializer.rb

jsonapi-materializer is a way to turn data objects (for example, active record models) into json:api responses.
Ruby
1
star
40

react-router-component-link.js

JavaScript
1
star
41

also.gem

Ruby
1
star
42

Seditor.app

A search and replace editor
JavaScript
1
star
43

blank-application

Elixir
1
star
44

netstring

Ruby
1
star
45

kristening

System for creating gender name change documents for transgender people.
Ruby
1
star
46

net-http-signature.gem

Handle signing HTTP requests/responses
Ruby
1
star
47

cluster-headache-tracker

Elixir
1
star
48

hypertext.gem

A HTML analysis and template engine
Ruby
1
star
49

ostruct.io

Io
1
star
50

snabbdom-view

Infuse your snabbdom components with "global" state.
JavaScript
1
star
51

rack-runtime.gem

A middleware for calculating and setting the Runtime header for the response
Ruby
1
star
52

rack-commonlogger.gem

The commonlogger middleware.
Ruby
1
star
53

parslet-export

A way to turn Parslet Parsers into other things
Ruby
1
star
54

scripts

Random scripts, tests, etc.
HTML
1
star
55

all-builtin-commands

A vscode extension
1
star
56

learn-you-the-web-for-everlasting-life

Darkness, Gloom, and Sparkle Elements! A book (and more) for learning HTML and CSS
JavaScript
1
star
57

accessor

Suggary Syntax and bonuses for accessors, getters, and setters
Ruby
1
star
58

ecto_interface.ex

Creates a common set of interface APIs for Ecto Schemas
Elixir
1
star