Class: Regexer::Models::Pattern
- Inherits:
-
Object
- Object
- Regexer::Models::Pattern
- Defined in:
- lib/regexer/models/pattern.rb
Overview
The main model for the patterns being build by pattern builder
Instance Attribute Summary collapse
-
#raw_pattern ⇒ Object
readonly
Returns the value of attribute raw_pattern.
Instance Method Summary collapse
- #+(other) ⇒ Object
-
#initialize(pattern, regex_escaped: true, single_entity: true, regex_shorthand_character: false) ⇒ Pattern
constructor
A new instance of Pattern.
- #regex ⇒ Object
- #regex_escaped? ⇒ Boolean
- #regex_shorthand_character? ⇒ Boolean
- #single_entity? ⇒ Boolean
Constructor Details
#initialize(pattern, regex_escaped: true, single_entity: true, regex_shorthand_character: false) ⇒ Pattern
Returns a new instance of Pattern.
11 12 13 14 15 16 |
# File 'lib/regexer/models/pattern.rb', line 11 def initialize(pattern, regex_escaped: true, single_entity: true, regex_shorthand_character: false) @raw_pattern = String.new(pattern) @regex_escaped = regex_escaped @single_entity = single_entity @regex_shorthand_character = regex_shorthand_character end |
Instance Attribute Details
#raw_pattern ⇒ Object (readonly)
Returns the value of attribute raw_pattern.
9 10 11 |
# File 'lib/regexer/models/pattern.rb', line 9 def raw_pattern @raw_pattern end |
Instance Method Details
#+(other) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/regexer/models/pattern.rb', line 18 def +(other) unless other.is_a?(Regexer::Models::Pattern) raise TypeError, "Unable to add #{other.class} to Regexer::Models::Pattern" end Regexer::Models::Pattern.new(@raw_pattern + other.raw_pattern, regex_escaped: @regex_escaped, single_entity: @single_entity) end |
#regex ⇒ Object
36 37 38 |
# File 'lib/regexer/models/pattern.rb', line 36 def regex /#{raw_pattern}/ end |
#regex_escaped? ⇒ Boolean
28 29 30 |
# File 'lib/regexer/models/pattern.rb', line 28 def regex_escaped? @regex_escaped end |
#regex_shorthand_character? ⇒ Boolean
40 41 42 |
# File 'lib/regexer/models/pattern.rb', line 40 def regex_shorthand_character? @regex_shorthand_character end |
#single_entity? ⇒ Boolean
32 33 34 |
# File 'lib/regexer/models/pattern.rb', line 32 def single_entity? @single_entity end |