Module: CEML::Script
- Defined in:
- lib/ceml/script.rb
Instance Method Summary collapse
- #allowed_roles ⇒ Object
- #asks(roles) ⇒ Object
- #concludes_immediately? ⇒ Boolean
- #dramatis_personae ⇒ Object (also: #dp)
- #expand_roles(roles) ⇒ Object
- #instructions_for(roles) ⇒ Object
- #label ⇒ Object
- #message? ⇒ Boolean
- #name ⇒ Object
- #params ⇒ Object
- #radius ⇒ Object
- #roles ⇒ Object
- #script ⇒ Object
- #simple? ⇒ Boolean
- #tell(roles) ⇒ Object
- #title ⇒ Object
- #to_hash(*fields) ⇒ Object
- #type ⇒ Object
- #validate! ⇒ Object
Instance Method Details
#allowed_roles ⇒ Object
93 94 95 96 97 |
# File 'lib/ceml/script.rb', line 93 def allowed_roles allowed_roles = [:organizer, :agents] allowed_roles += casting_statement.roles unless casting_statement.empty? allowed_roles end |
#asks(roles) ⇒ Object
48 49 50 51 |
# File 'lib/ceml/script.rb', line 48 def asks(roles) return [] if instructions.empty? instructions.asks([*roles]) end |
#concludes_immediately? ⇒ Boolean
99 100 101 |
# File 'lib/ceml/script.rb', line 99 def concludes_immediately? !title and instructions.asks([:agents]).empty? end |
#dramatis_personae ⇒ Object Also known as: dp
29 30 31 |
# File 'lib/ceml/script.rb', line 29 def dramatis_personae casting_statement.empty? ? nil : casting_statement end |
#expand_roles(roles) ⇒ Object
39 40 41 |
# File 'lib/ceml/script.rb', line 39 def (roles) roles.map{ |r| r == :agent ? [:agent, :agents] : r }.flatten.concat([:both, :all, :everyone]) end |
#instructions_for(roles) ⇒ Object
43 44 45 46 |
# File 'lib/ceml/script.rb', line 43 def instructions_for(roles) return [] if !instructions or instructions.empty? return instructions.for((roles)) end |
#label ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/ceml/script.rb', line 76 def label return title || begin return "unknown" unless simple? if q = instructions.asks(:agents).first "Question: #{q.text}" elsif tell = instructions.tell(:agents) "Message: #{tell}" if tell else "unknown" end end end |
#message? ⇒ Boolean
72 73 74 |
# File 'lib/ceml/script.rb', line 72 def type == 'message' end |
#name ⇒ Object
16 17 18 |
# File 'lib/ceml/script.rb', line 16 def name title || label end |
#params ⇒ Object
53 54 55 56 57 |
# File 'lib/ceml/script.rb', line 53 def params asks(:organizer).map do |ask| [ask.var, ask.var.capitalize, ask.text] end end |
#radius ⇒ Object
20 21 22 |
# File 'lib/ceml/script.rb', line 20 def radius casting_statement.empty? ? nil : casting_statement.radius end |
#roles ⇒ Object
24 25 26 27 |
# File 'lib/ceml/script.rb', line 24 def roles return [:agents] if casting_statement.empty? return casting_statement.roles end |
#script ⇒ Object
8 9 10 |
# File 'lib/ceml/script.rb', line 8 def script text_value end |
#simple? ⇒ Boolean
35 36 37 |
# File 'lib/ceml/script.rb', line 35 def simple? (roles - [:agents, :organizer]).empty? end |
#tell(roles) ⇒ Object
59 60 61 62 |
# File 'lib/ceml/script.rb', line 59 def tell(roles) return nil if instructions.empty? instructions.tell([*roles]) end |
#title ⇒ Object
12 13 14 |
# File 'lib/ceml/script.rb', line 12 def title super && !super.empty? && super.value end |
#to_hash(*fields) ⇒ Object
4 5 6 |
# File 'lib/ceml/script.rb', line 4 def to_hash *fields fields.inject({}){ |h, s| x = send(s); h[s] = x if x; h } end |
#type ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/ceml/script.rb', line 64 def type return 'mission' if title return 'unknown' if instructions.empty? return 'question' if not instructions.asks.empty? return 'message' if instructions.tell(:agents) return 'unknown' end |
#validate! ⇒ Object
89 90 91 |
# File 'lib/ceml/script.rb', line 89 def validate! instructions.validate!(allowed_roles) unless instructions.empty? end |