Module: ActivityStreams::Matchers
Overview
Provides a number of generally useful utilities methods
Class Method Summary collapse
-
.checker(&block) ⇒ Object
utility method providing the basic structure of validation checkers for the various fields…
-
.is_absolute_iri?(m) ⇒ Boolean
true if m is parseable as an IRI and is absolute.
-
.is_lang_tag?(m) ⇒ Boolean
true if m is a valid RFC 4646 Lang tag.
-
.is_mime_type?(m) ⇒ Boolean
true if m is a valid MIME Media Type.
-
.is_token?(m) ⇒ Boolean
true if m validates as a isegment-nz-nc as defined by RFC 3987.
-
.is_verb?(m) ⇒ Boolean
true if m is a valid verb.
Class Method Details
.checker(&block) ⇒ Object
utility method providing the basic structure of validation checkers for the various fields…
98 99 100 101 102 103 |
# File 'lib/streams/activitystreams.rb', line 98 def checker &block ->(v) do raise ArgumentError unless block.call v v end end |
.is_absolute_iri?(m) ⇒ Boolean
true if m is parseable as an IRI and is absolute
77 78 79 |
# File 'lib/streams/activitystreams.rb', line 77 def is_absolute_iri? m URI.parse(m).absolute? rescue false end |
.is_lang_tag?(m) ⇒ Boolean
true if m is a valid RFC 4646 Lang tag
92 93 94 |
# File 'lib/streams/activitystreams.rb', line 92 def is_lang_tag? m I18n::Locale::Tag::Rfc4646.tag m rescue false end |
.is_mime_type?(m) ⇒ Boolean
true if m is a valid MIME Media Type
87 88 89 |
# File 'lib/streams/activitystreams.rb', line 87 def is_mime_type? m MIME::Type.new m rescue false end |
.is_token?(m) ⇒ Boolean
true if m validates as a isegment-nz-nc as defined by RFC 3987. The activity streams spec requires that verbs and object types MUST either be isegment-nz-nc or absolute IRI productions.
70 71 72 73 74 |
# File 'lib/streams/activitystreams.rb', line 70 def is_token? m return false if m == nil m = m.to_s (m =~ /^([a-zA-Z0-9\-\.\_\~]|\%[0-9a-fA-F]{2}|[\!\$\&\'\(\)\*\+\,\;\=\@])+$/) != nil end |
.is_verb?(m) ⇒ Boolean
true if m is a valid verb
82 83 84 |
# File 'lib/streams/activitystreams.rb', line 82 def is_verb? m is_token?(m) || is_absolute_iri?(m) end |