Class: Hexpress
- Includes:
- Web
- Defined in:
- lib/hexpress.rb,
lib/hexpress/web.rb,
lib/hexpress/value.rb,
lib/hexpress/nested.rb,
lib/hexpress/values.rb,
lib/hexpress/version.rb,
lib/hexpress/wrapped.rb,
lib/hexpress/modifier.rb,
lib/hexpress/character.rb,
lib/hexpress/value/with.rb,
lib/hexpress/nested/find.rb,
lib/hexpress/modifier/one.rb,
lib/hexpress/value/ending.rb,
lib/hexpress/value/except.rb,
lib/hexpress/values/range.rb,
lib/hexpress/modifier/many.rb,
lib/hexpress/values/either.rb,
lib/hexpress/value/starting.rb,
lib/hexpress/nested/matching.rb,
lib/hexpress/verbal_expressions.rb
Defined Under Namespace
Modules: Modifier, Nested, Value, Values, Web, Wrapped Classes: Character
Constant Summary collapse
- CHARACTERS =
[:word, :digit, :space]
- VERSION =
"1.2.0"
Instance Attribute Summary collapse
-
#expressions ⇒ Object
readonly
Returns the value of attribute expressions.
Instance Method Summary collapse
-
#+(expression) ⇒ Object
Takes an expression and returns the combination of the two expressions in a new Hexpress object.
- #add_values(hexpression, *vs) ⇒ Object
-
#any ⇒ Object
Matches .
-
#anything ⇒ Object
Matches (?:.)*.
- #anythingBut(value) ⇒ Object
-
#digit ⇒ Object
Matches d.
- #either(*values) ⇒ Object (also: #and, #any_of, #anyOf)
- #ending(value = nil) ⇒ Object (also: #ending_with, #finally, #endOfLine)
- #except(value) ⇒ Object (also: #excluding, #exclude, #without)
- #find(value = nil, &block) ⇒ Object (also: #capture)
-
#initialize(*expressions, &block) ⇒ Hexpress
constructor
A new instance of Hexpress.
- #letter ⇒ Object
-
#line ⇒ Object
(also: #lineBreak, #br)
Matches (?:(?:n)|(?:rn)).
- #lower(value = "a".."z") ⇒ Object
- #many(value = nil, minimum = 1) ⇒ Object (also: #multiple)
- #matching(&block) ⇒ Object (also: #like)
- #number(value = 0..9) ⇒ Object
- #one(value = nil, &block) ⇒ Object (also: #maybe, #possibly)
-
#something ⇒ Object
Matches (?:.)+.
- #somethingBut(value) ⇒ Object
-
#space ⇒ Object
Matches s.
- #starting(value = nil) ⇒ Object (also: #begins, #begin, #start, #startOfLine)
-
#tab ⇒ Object
Matches t.
-
#to_r ⇒ Object
This method returns the regular hexpression form of this object.
-
#to_s ⇒ Object
This method returns the string version of the regexp.
- #upper(value = "A".."Z") ⇒ Object
- #with(value) ⇒ Object (also: #has, #including, #then)
-
#word ⇒ Object
Matches w.
Methods included from Web
#domain, #ftp, #ftp_only, #ftps_only, #http, #http_only, #https_only, #path, #protocol, #tld
Constructor Details
#initialize(*expressions, &block) ⇒ Hexpress
Returns a new instance of Hexpress.
5 6 7 8 |
# File 'lib/hexpress.rb', line 5 def initialize(*expressions, &block) @expressions = expressions instance_exec(&block) if block_given? end |
Instance Attribute Details
#expressions ⇒ Object (readonly)
Returns the value of attribute expressions.
3 4 5 |
# File 'lib/hexpress.rb', line 3 def expressions @expressions end |
Instance Method Details
#+(expression) ⇒ Object
Takes an expression and returns the combination of the two expressions in a new Hexpress object.
80 81 82 |
# File 'lib/hexpress.rb', line 80 def +(expression) Hexpress.new(*expressions + expression.expressions) end |
#add_values(hexpression, *vs) ⇒ Object
2 3 4 |
# File 'lib/hexpress/values.rb', line 2 def add_values(hexpression, *vs) add(hexpression.new(*vs)) end |
#any ⇒ Object
Matches .
26 27 28 |
# File 'lib/hexpress.rb', line 26 def any add(Character.new(:any)) end |
#anything ⇒ Object
Matches (?:.)*
31 32 33 |
# File 'lib/hexpress.rb', line 31 def anything many(Character.new(:any), 0) end |
#anythingBut(value) ⇒ Object
10 11 12 |
# File 'lib/hexpress/verbal_expressions.rb', line 10 def anythingBut(value) many(matching { without(value) }.to_s, 0) end |
#digit ⇒ Object
Matches d
16 17 18 |
# File 'lib/hexpress.rb', line 16 def digit add(Character.new(:digit)) end |
#either(*values) ⇒ Object Also known as: and, any_of, anyOf
2 3 4 |
# File 'lib/hexpress/values/either.rb', line 2 def either(*values) add_value(Values::Either, values) end |
#ending(value = nil) ⇒ Object Also known as: ending_with, finally, endOfLine
2 3 4 |
# File 'lib/hexpress/value/ending.rb', line 2 def ending(value = nil) add_value(Value::Ending, value) end |
#except(value) ⇒ Object Also known as: excluding, exclude, without
2 3 4 |
# File 'lib/hexpress/value/except.rb', line 2 def except(value) add_value(Value::Except, value) end |
#find(value = nil, &block) ⇒ Object Also known as: capture
2 3 4 |
# File 'lib/hexpress/nested/find.rb', line 2 def find(value = nil, &block) value ? add_value(Nested::Find, value) : add_nested(Nested::Find, &block) end |
#letter ⇒ Object
2 3 4 |
# File 'lib/hexpress/values/range.rb', line 2 def letter lower and upper end |
#line ⇒ Object Also known as: lineBreak, br
Matches (?:(?:n)|(?:rn))
46 47 48 |
# File 'lib/hexpress.rb', line 46 def line either(Character.new('(?:\n)'), Character.new('(?:\r\n)')) end |
#lower(value = "a".."z") ⇒ Object
6 7 8 |
# File 'lib/hexpress/values/range.rb', line 6 def lower(value = "a".."z") add_value(Values::Range, value) end |
#many(value = nil, minimum = 1) ⇒ Object Also known as: multiple
2 3 4 |
# File 'lib/hexpress/modifier/many.rb', line 2 def many(value = nil, minimum = 1) add_values(Modifier::Many, value, minimum) end |
#matching(&block) ⇒ Object Also known as: like
2 3 4 |
# File 'lib/hexpress/nested/matching.rb', line 2 def matching(&block) add_nested(Nested::Matching, &block) end |
#number(value = 0..9) ⇒ Object
14 15 16 |
# File 'lib/hexpress/values/range.rb', line 14 def number(value = 0..9) add_value(Values::Range, value) end |
#one(value = nil, &block) ⇒ Object Also known as: maybe, possibly
2 3 4 |
# File 'lib/hexpress/modifier/one.rb', line 2 def one(value = nil, &block) add_value(Modifier::One, value, &block) end |
#something ⇒ Object
Matches (?:.)+
36 37 38 |
# File 'lib/hexpress.rb', line 36 def something many(Character.new(:any), 1) end |
#somethingBut(value) ⇒ Object
14 15 16 |
# File 'lib/hexpress/verbal_expressions.rb', line 14 def somethingBut(value) something and without(value) end |
#space ⇒ Object
Matches s
21 22 23 |
# File 'lib/hexpress.rb', line 21 def space add(Character.new(:space)) end |
#starting(value = nil) ⇒ Object Also known as: begins, begin, start, startOfLine
2 3 4 |
# File 'lib/hexpress/value/starting.rb', line 2 def starting(value = nil) add_value(Value::Starting, value) end |
#tab ⇒ Object
Matches t
41 42 43 |
# File 'lib/hexpress.rb', line 41 def tab add(Character.new(:tab)) end |
#to_r ⇒ Object
This method returns the regular hexpression form of this object.
69 70 71 |
# File 'lib/hexpress.rb', line 69 def to_r Regexp.new(to_s) end |
#to_s ⇒ Object
This method returns the string version of the regexp.
74 75 76 |
# File 'lib/hexpress.rb', line 74 def to_s @expressions.map(&:to_s).join end |
#upper(value = "A".."Z") ⇒ Object
10 11 12 |
# File 'lib/hexpress/values/range.rb', line 10 def upper(value = "A".."Z") add_value(Values::Range, value) end |