Class: Structr::FieldDefinition
- Inherits:
-
Object
- Object
- Structr::FieldDefinition
- Defined in:
- lib/structr.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
Returns the value of attribute block.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #getter ⇒ Object
-
#initialize(name, regexp, &block) ⇒ FieldDefinition
constructor
A new instance of FieldDefinition.
- #ivar ⇒ Object
- #match(string) ⇒ Object
- #setter ⇒ Object
Constructor Details
#initialize(name, regexp, &block) ⇒ FieldDefinition
Returns a new instance of FieldDefinition.
84 85 86 |
# File 'lib/structr.rb', line 84 def initialize(name, regexp, &block) @name, @regexp, @block = name.to_s, regexp, block end |
Instance Attribute Details
#block ⇒ Object
Returns the value of attribute block.
82 83 84 |
# File 'lib/structr.rb', line 82 def block @block end |
#name ⇒ Object
Returns the value of attribute name.
82 83 84 |
# File 'lib/structr.rb', line 82 def name @name end |
Instance Method Details
#getter ⇒ Object
92 93 94 |
# File 'lib/structr.rb', line 92 def getter :"#{name}" end |
#ivar ⇒ Object
96 97 98 |
# File 'lib/structr.rb', line 96 def ivar :"@#{name}" end |
#match(string) ⇒ Object
100 101 102 103 104 105 106 107 108 109 |
# File 'lib/structr.rb', line 100 def match(string) string.scan(@regexp).map do |matched| matched = matched.first if matched.size == 1 if @block @block.call(*matched) else matched end end end |
#setter ⇒ Object
88 89 90 |
# File 'lib/structr.rb', line 88 def setter :"#{name}=" end |