Class: Krill::ShowBlock
- Inherits:
-
Object
- Object
- Krill::ShowBlock
- Defined in:
- lib/krill/show_block.rb
Overview
The ShowBlock class implements the methods inside show blocks, which are used to interact with the technician. When a show block is encountered, it is used to construct a page of instructions for the technician. Execution is suspended until the user clicks "OK" in the protocol. The show method returns a ShowResponse object that contains any information entered by the user via get, select, or table inputs.
Instance Method Summary collapse
-
#bullet(str) ⇒ void
Put the string s on the page, with a bullet in front of it, as in a bullet list.
-
#check(str) ⇒ void
Put the string s on the page, with a clickable checkbox in front of it.
-
#get(type, opts = {}) ⇒ void
Display an input box to the user to obtain data of some kind.
-
#image(name) ⇒ Object
Display the image pointed to by name on the page.
-
#item(i) ⇒ void
Display information about the item i -- its id, its location, its object type, and its sample type (if any) -- so that the user can find it.
-
#note(str) ⇒ void
Put the string s in a smaller font on the page.
-
#select(choices, opts = {}) ⇒ void
Display a selection of choices for the user.
-
#separator ⇒ void
Display a break between other shown elements, such as between two notes.
-
#table(m) ⇒ void
Display a table represented by the matrix t.
-
#timer(opts = {}) ⇒ void
Show a rudimentary timer.
-
#title(str) ⇒ void
Put the string s at the top of the page.
-
#upload(opts = {}) ⇒ void
Upload a file.
-
#warning(str) ⇒ void
Put the string s in bold, eye catching font on the page in hopes that the user might notice it and heed your advice.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
303 304 305 306 307 308 309 310 311 |
# File 'lib/krill/show_block.rb', line 303 def method_missing(m, *args, &block) raise "Cannot call 'show' within a show block." if m == :show if @base.methods.include?(m) @base.send(m, *args, &block) else super end end |
Instance Method Details
#bullet(str) ⇒ void
This method returns an undefined value.
Put the string s on the page, with a bullet in front of it, as in a bullet list. If an array of strings is passed, then a bullet is made for each element of the array.
91 92 93 |
# File 'lib/krill/show_block.rb', line 91 def bullet(str) [*str].each { |s| @parts.push(bullet: s) } end |
#check(str) ⇒ void
This method returns an undefined value.
Put the string s on the page, with a clickable checkbox in front of it. The user will need to click all checkboxes on a given page before the "OK" button is enabled. If an array of strings is passed, then a checkbox is made for each element of the array.
83 84 85 |
# File 'lib/krill/show_block.rb', line 83 def check(str) [*str].each { |s| @parts.push(check: s) } end |
#get(type, opts = {}) ⇒ void
This method returns an undefined value.
Display an input box to the user to obtain data of some kind. If no options are supplied, then the data is stored in a ShowResponse object returned by the show function with a key called something like get_12 or get_13 (for get number 12 or get number 13). The name of the variable name can be specified via the var option. A label for the input box can also be specified.
243 244 245 246 247 248 249 250 251 252 |
# File 'lib/krill/show_block.rb', line 243 def get(type, opts = {}) raise "First argument to get should be either 'number' or 'text'" unless type == 'number' || type == 'text' = { var: "get_#{@@get_counter}", label: "Enter a #{type}" } @@get_counter += 1 @parts.push(input: (.merge opts).merge(type: type)) end |
#image(name) ⇒ Object
Display the image pointed to by name on the page. The name argument will be prepended by the URL to the S3 url defined by Bioturk::Application.config.image_server_interface in config/initializers/aquarium.rb
157 158 159 |
# File 'lib/krill/show_block.rb', line 157 def image(name) @parts.push(image: "#{Bioturk::Application.config.image_server_interface}#{name}") end |
#item(i) ⇒ void
This method returns an undefined value.
Display information about the item i -- its id, its location, its object type, and its sample type (if any) -- so that the user can find it.
133 134 135 |
# File 'lib/krill/show_block.rb', line 133 def item(i) @parts.push(take: i) end |
#note(str) ⇒ void
This method returns an undefined value.
Put the string s in a smaller font on the page. Often called several times. If an array of strings is passed, then a note is made for each element of the array.
59 60 61 |
# File 'lib/krill/show_block.rb', line 59 def note(str) [*str].each { |s| @parts.push(note: s) } end |
#select(choices, opts = {}) ⇒ void
This method returns an undefined value.
Display a selection of choices for the user. The options are the same as for get. For example,
param choices [List] A list of choices, either all strings or all numbers
283 284 285 286 287 288 289 290 291 292 293 294 |
# File 'lib/krill/show_block.rb', line 283 def select(choices, opts = {}) choices = choices.uniq raise 'First argument to select should be an array of numbers or strings' unless ShowBlock.is_proper_array choices = { var: "select_#{@@select_counter}", label: 'Choose', multiple: false } @@select_counter += 1 @parts.push(select: (.merge opts).merge(choices: choices)) end |
#separator ⇒ void
This method returns an undefined value.
Display a break between other shown elements, such as between two notes.
146 147 148 |
# File 'lib/krill/show_block.rb', line 146 def separator @parts.push(separator: true) end |
#table(m) ⇒ void
This method returns an undefined value.
Display a table represented by the matrix t. The method takes a 2x2 list of either numbers, strings, or hashes. In the case of hashes, the following fields can be present.
content: A number or string check: Whether the entry is checkable, true or false style: A hash containing css
See the Operations documentation for more information about how to construct tables automatically based on the inputs and outputs to a protocol's operation.
121 122 123 124 125 126 127 |
# File 'lib/krill/show_block.rb', line 121 def table(m) if m.class == Table @parts.push(table: m.all.render) else @parts.push(table: m) end end |
#timer(opts = {}) ⇒ void
This method returns an undefined value.
Show a rudimentary timer. By default, the timer starts at one minute and counts down. It starts beeping when it gets to zero, and keeps beeping until the user clicks "OK". You can specify the starting number of hours, minutes, and seconds, with for example The initial option can be used to set the initial time on the timer and has field hours, minutes, and seconds, all numerical.
171 172 173 174 175 176 177 178 |
# File 'lib/krill/show_block.rb', line 171 def timer(opts = {}) = { initial: { hours: 0, minutes: 1, seconds: 0 }, final: { hours: 0, minutes: 0, seconds: 0 }, direction: 'down' }.merge opts @parts.push(timer: ) end |
#title(str) ⇒ void
This method returns an undefined value.
Put the string s at the top of the page. Usually only called once in a given call to show.
51 52 53 |
# File 'lib/krill/show_block.rb', line 51 def title(str) @parts.push(title: str) end |
#upload(opts = {}) ⇒ void
This method returns an undefined value.
Upload a file. The optional name specified by the :var option can be used to retrieve the upload.
See the [ShowResponse] documentation for how to manipulate uploads.
189 190 191 192 193 194 195 |
# File 'lib/krill/show_block.rb', line 189 def upload(opts = {}) = { var: "upload_#{@@upload_counter}" } @@upload_counter += 1 @parts.push(upload: .merge(opts)) end |
#warning(str) ⇒ void
This method returns an undefined value.
Put the string s in bold, eye catching font on the page in hopes that the user might notice it and heed your advice.
74 75 76 |
# File 'lib/krill/show_block.rb', line 74 def warning(str) @parts.push(warning: str) end |