Class: CARPS::Sheet::Editor
- Inherits:
-
Object
- Object
- CARPS::Sheet::Editor
- Defined in:
- lib/carps/mod/sheet/editor.rb
Overview
Editor for a character sheet
Performs validations also, popping open an editor if they fail
Instance Method Summary collapse
-
#fill(sheet) ⇒ Object
Fill in the sheet.
-
#initialize(schema, semantics) ⇒ Editor
constructor
A new instance of Editor.
-
#valid?(sheet) ⇒ Boolean
Is the sheet valid?.
-
#validate(sheet) ⇒ Object
Edit the sheet until it is valid.
Constructor Details
#initialize(schema, semantics) ⇒ Editor
Returns a new instance of Editor.
32 33 34 35 |
# File 'lib/carps/mod/sheet/editor.rb', line 32 def initialize schema, semantics @schema = schema @semantics = semantics end |
Instance Method Details
#fill(sheet) ⇒ Object
Fill in the sheet
38 39 40 41 |
# File 'lib/carps/mod/sheet/editor.rb', line 38 def fill sheet edit sheet validate sheet end |
#valid?(sheet) ⇒ Boolean
Is the sheet valid?
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/carps/mod/sheet/editor.rb', line 44 def valid? sheet failures = @schema.produce_errors sheet unless failures failures = @semantics.produce_errors sheet end if failures UI::put_error "Character sheet was incorrect:" failures.each do |f| puts f end return false else return true end end |
#validate(sheet) ⇒ Object
Edit the sheet until it is valid
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/carps/mod/sheet/editor.rb', line 61 def validate sheet valid = false until valid if sheet valid = valid? sheet end unless valid edit sheet end end end |