Class: JsDuck::ExternalClasses
- Inherits:
-
Object
- Object
- JsDuck::ExternalClasses
- Defined in:
- lib/jsduck/external_classes.rb
Overview
Handles patterns of external classes.
A pattern can be a simple classname or a one with a wildcard “*”.
Instance Method Summary collapse
-
#initialize(classnames = []) ⇒ ExternalClasses
constructor
A new instance of ExternalClasses.
-
#is?(classname) ⇒ Boolean
True if the classname matches an external class pattern.
- #make_pattern(pattern) ⇒ Object
Constructor Details
#initialize(classnames = []) ⇒ ExternalClasses
Returns a new instance of ExternalClasses.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/jsduck/external_classes.rb', line 8 def initialize(classnames = []) @class_names = {} @patterns = [] classnames.each do |name| if name =~ /\*/ @patterns << make_pattern(name) else @class_names[name] = true end end end |
Instance Method Details
#is?(classname) ⇒ Boolean
True if the classname matches an external class pattern.
21 22 23 |
# File 'lib/jsduck/external_classes.rb', line 21 def is?(classname) @class_names[classname] || @patterns.any? {|p| classname =~ p } end |
#make_pattern(pattern) ⇒ Object
25 26 27 |
# File 'lib/jsduck/external_classes.rb', line 25 def make_pattern(pattern) Regexp.new("^" + pattern.split(/\*/, -1).map {|s| Regexp.escape(s) }.join(".*") + "$") end |