Class: PatternRuby::EntityTypes::Registry
- Inherits:
-
Object
- Object
- PatternRuby::EntityTypes::Registry
- Defined in:
- lib/pattern_ruby/entity_types.rb
Instance Method Summary collapse
- #get(name) ⇒ Object
-
#initialize ⇒ Registry
constructor
A new instance of Registry.
- #parse(name, raw_value) ⇒ Object
- #pattern_for(name) ⇒ Object
- #register(name, pattern: nil, parser: nil) ⇒ Object
Constructor Details
Instance Method Details
#get(name) ⇒ Object
49 50 51 |
# File 'lib/pattern_ruby/entity_types.rb', line 49 def get(name) @mutex.synchronize { @types[name.to_sym] } end |
#parse(name, raw_value) ⇒ Object
58 59 60 61 62 |
# File 'lib/pattern_ruby/entity_types.rb', line 58 def parse(name, raw_value) type = get(name) return raw_value unless type && type[:parser] type[:parser].call(raw_value) end |
#pattern_for(name) ⇒ Object
53 54 55 56 |
# File 'lib/pattern_ruby/entity_types.rb', line 53 def pattern_for(name) type = get(name) type && type[:pattern] end |
#register(name, pattern: nil, parser: nil) ⇒ Object
43 44 45 46 47 |
# File 'lib/pattern_ruby/entity_types.rb', line 43 def register(name, pattern: nil, parser: nil) @mutex.synchronize do @types[name.to_sym] = { pattern: pattern, parser: parser } end end |