Class: Nemo::Examples::PersonEditor::Person

Inherits:
Object
  • Object
show all
Defined in:
lib/nemo/examples/person_editor.rb

Constant Summary collapse

INTERESTS =
['Art', 'Music', 'Coffee', 'Ruby']

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePerson

Returns a new instance of Person.



231
232
233
234
235
# File 'lib/nemo/examples/person_editor.rb', line 231

def initialize
  @interests = ['Art', 'Music']
  @password = 'abc123'
  @phone_numbers = Array.new
end

Instance Attribute Details

#birthdayObject

Returns the value of attribute birthday.



229
230
231
# File 'lib/nemo/examples/person_editor.rb', line 229

def birthday
  @birthday
end

#fatherObject

Returns the value of attribute father.



229
230
231
# File 'lib/nemo/examples/person_editor.rb', line 229

def father
  @father
end

#interestsObject

Returns the value of attribute interests.



229
230
231
# File 'lib/nemo/examples/person_editor.rb', line 229

def interests
  @interests
end

#motherObject

Returns the value of attribute mother.



229
230
231
# File 'lib/nemo/examples/person_editor.rb', line 229

def mother
  @mother
end

#nameObject

Returns the value of attribute name.



229
230
231
# File 'lib/nemo/examples/person_editor.rb', line 229

def name
  @name
end

#passwordObject

Returns the value of attribute password.



229
230
231
# File 'lib/nemo/examples/person_editor.rb', line 229

def password
  @password
end

#phone_numbersObject

Returns the value of attribute phone_numbers.



229
230
231
# File 'lib/nemo/examples/person_editor.rb', line 229

def phone_numbers
  @phone_numbers
end

#sexObject

Returns the value of attribute sex.



229
230
231
# File 'lib/nemo/examples/person_editor.rb', line 229

def sex
  @sex
end

Instance Method Details

#ageObject



237
238
239
240
# File 'lib/nemo/examples/person_editor.rb', line 237

def age
  date = (@birthday || Date.today-1)
  (Date.today-date).to_i/365
end

#metaobjectObject



242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
# File 'lib/nemo/examples/person_editor.rb', line 242

def metaobject
  Nemo.metaobject_for(self) {
    text :name
      label 'Full Name'
      maxlength 30
      required
    
    password :password
      label 'Password'
      required
    
    date :birthday
      label 'Birthday'
      format_with { |date| date.strftime('%b %d, %Y') }
      required
    
    text :age
      label 'Age'
      read_only
    
    boolean :sex
      label 'Sex'
      true_item_string 'male'
      false_item_string 'female'
    
    single_relationship :father
      label 'Father'
      relationship_to { Wee::Session.current.domainmodel.male_persons }
      format_with { |each| sprintf('%s (%s)', each.name, each.metaobject[:sex].formatted_value) }
      nil_item_string 'unknown'
    
    single_relationship :mother
      label 'Mother'
      relationship_to { Wee::Session.current.domainmodel.female_persons }
      format_with { |each| sprintf('%s (%s)', each.name, each.metaobject[:sex].formatted_value) }
      nil_item_string 'unknown'
      link_action { |item| puts "==== Action was taken ====" }
    
    multiple_relationship :interests
      label 'Interests'
      relationship_to { INTERESTS }
      add_validation_rule { |value| value.size > 1 }.
        error_string('Select at least two items of interest')

    multiple :phone_numbers
      label 'Phone#s'
      base_class Nemo::Examples::PersonEditor::PhoneNumber
      format_with { |each| sprintf('%s: %s', each.type, each.number) }
  }
end