Class: CARPS::Sheet::Editor

Inherits:
Object
  • Object
show all
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

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?

Returns:

  • (Boolean)


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