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.
83 84 85 |
# File 'lib/structr.rb', line 83 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.
81 82 83 |
# File 'lib/structr.rb', line 81 def block @block end |
#name ⇒ Object
Returns the value of attribute name.
81 82 83 |
# File 'lib/structr.rb', line 81 def name @name end |
Instance Method Details
#getter ⇒ Object
91 92 93 |
# File 'lib/structr.rb', line 91 def getter :"#{name}" end |
#ivar ⇒ Object
95 96 97 |
# File 'lib/structr.rb', line 95 def ivar :"@#{name}" end |
#match(string) ⇒ Object
99 100 101 102 103 104 105 106 107 108 |
# File 'lib/structr.rb', line 99 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
87 88 89 |
# File 'lib/structr.rb', line 87 def setter :"#{name}=" end |