Class: Structr::FieldDefinition

Inherits:
Object
  • Object
show all
Defined in:
lib/structr.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#blockObject

Returns the value of attribute block.



81
82
83
# File 'lib/structr.rb', line 81

def block
  @block
end

#nameObject

Returns the value of attribute name.



81
82
83
# File 'lib/structr.rb', line 81

def name
  @name
end

Instance Method Details

#getterObject



91
92
93
# File 'lib/structr.rb', line 91

def getter
  :"#{name}"
end

#ivarObject



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

#setterObject



87
88
89
# File 'lib/structr.rb', line 87

def setter
  :"#{name}="
end