Class: ArchUnit::GraphReporting::Projection::PatternCollapse
- Inherits:
-
Data
- Object
- Data
- ArchUnit::GraphReporting::Projection::PatternCollapse
- Defined in:
- lib/archunit/graph/projection/pattern_collapse.rb
Overview
Collapse nodes by applying a regular-expression replacement.
Instance Attribute Summary collapse
-
#regexp ⇒ Object
readonly
Returns the value of attribute regexp.
-
#replacement ⇒ Object
readonly
Returns the value of attribute replacement.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(regexp:, replacement: '\\1') ⇒ PatternCollapse
constructor
A new instance of PatternCollapse.
Constructor Details
#initialize(regexp:, replacement: '\\1') ⇒ PatternCollapse
Returns a new instance of PatternCollapse.
8 9 10 11 12 13 |
# File 'lib/archunit/graph/projection/pattern_collapse.rb', line 8 def initialize(regexp:, replacement: '\\1') raise ArgumentError, 'regexp must be a Regexp' unless regexp.is_a?(Regexp) raise ArgumentError, 'replacement must be a String' unless replacement.is_a?(String) super(regexp: regexp.dup.freeze, replacement: replacement.dup.freeze) end |
Instance Attribute Details
#regexp ⇒ Object (readonly)
Returns the value of attribute regexp
7 8 9 |
# File 'lib/archunit/graph/projection/pattern_collapse.rb', line 7 def regexp @regexp end |
#replacement ⇒ Object (readonly)
Returns the value of attribute replacement
7 8 9 |
# File 'lib/archunit/graph/projection/pattern_collapse.rb', line 7 def replacement @replacement end |
Class Method Details
.from(pattern, replacement = '\\1') ⇒ Object
15 16 17 18 19 20 |
# File 'lib/archunit/graph/projection/pattern_collapse.rb', line 15 def self.from(pattern, replacement = '\\1') regexp = pattern.is_a?(String) ? Regexp.new(pattern) : pattern new(regexp:, replacement:) rescue RegexpError => e raise ArgumentError, "invalid collapse pattern: #{e.}" end |