Code Monkey home page Code Monkey logo

mruby-publicsuffix's Introduction

mruby-publicsuffix Build Status

Public Suffix List for mruby. The purpose of this project is mruby port of publicsuffix-ruby.

NOTE

mruby-publicsuffix aims at porting from publicsuffix-ruby, but there's some differences, so it cannot provide totally the same functionality.

Requirements

  • mruby >= 1.3.0

Installation

You can add conf.gem line to build_config.rb:

MRuby::Build.new do |conf|

    # ... (snip) ...

    conf.gem mgem: 'mruby-publicsuffix'
end

PublicSuffix class methods

PublicSuffix.domain

PublicSuffix.domain extracts the domain out from a given name and returns it as String class.

PublicSuffix.domain('google.com')
# => "google.com"

If given a domain with subdomains, returning the domain.

PublicSuffix.domain('www.google.com')
# => "google.com"
PublicSuffix.domain('www.google.co.uk')
# => "google.co.uk"

This library automatically recognizes FQDN (Fully Qualified Domain Names). A FQDN is a domain name that end with a trailing dot.

PublicSuffix.domain("www.google.com.")
# => "google.com"

PublicSuffix.parse

PublicSuffix.parse parses a domain and returns an object of PublicSuffix::Domain class. This method support a domain with subdomains.

domain = PublicSuffix.parse('www.google.com')
# => #<PublicSuffix::Domain:0x7fa3bf84c9b0>

PublicSuffix.valid?

Checks whether a given domain is assigned and allowed, without actually parsing it. This method doesn't care whether domain is a domain or subdomain. The validation is performed using the default PublicSuffix::List.

Simple validation example:

PublicSuffix.valid?("google.com")
# => true

# Explicitly forbidden, it is listed as a private domain
> PublicSuffix.valid?("blogspot.com")
# => false

# Unknown/not-listed TLD domains are valid by default
> PublicSuffix.valid?("example.tldnotlisted")
# => true

Strict validation (without applying the default * rule):

> PublicSuffix.valid?("example.tldnotlisted", PublicSuffix::List.default, nil)
# => false

License

under the MIT License:

  • see LICENSE file

mruby-publicsuffix's People

Contributors

hfm avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.