Class: Livetext::Variables
- Defined in:
- lib/livetext/variables.rb,
lib/livetext/skeleton.rb
Overview
FIXME - split out into file as Livetext::Variables
Instance Attribute Summary collapse
-
#vars ⇒ Object
readonly
Returns the value of attribute vars.
Instance Method Summary collapse
- #[](var) ⇒ Object
- #[]=(var, value) ⇒ Object
- #get(var) ⇒ Object
-
#initialize(hash = {}) ⇒ Variables
constructor
Livetext::Variables.
- #inspect ⇒ Object
- #set(var, value) ⇒ Object
- #setvars(pairs) ⇒ Object
- #to_a ⇒ Object
Constructor Details
#initialize(hash = {}) ⇒ Variables
Livetext::Variables
4 5 6 7 8 9 10 11 12 |
# File 'lib/livetext/variables.rb', line 4 def initialize(hash = {}) # Livetext::Variables @vars = {} hash.each_pair do |k, v| sym = k.to_sym str = k.to_s @vars[sym] = v @vars[str] = v end end |
Instance Attribute Details
#vars ⇒ Object (readonly)
Returns the value of attribute vars.
2 3 4 |
# File 'lib/livetext/variables.rb', line 2 def vars @vars end |
Instance Method Details
#[](var) ⇒ Object
23 24 25 |
# File 'lib/livetext/variables.rb', line 23 def [](var) @vars[var.to_sym] end |
#[]=(var, value) ⇒ Object
27 28 29 |
# File 'lib/livetext/variables.rb', line 27 def []=(var, value) @vars[var.to_sym] = value end |
#get(var) ⇒ Object
31 32 33 |
# File 'lib/livetext/variables.rb', line 31 def get(var) @vars[var.to_sym] || "[#{var} is undefined]" end |
#inspect ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/livetext/variables.rb', line 14 def inspect syms = @vars.keys.select {|x| x.is_a? Symbol } out = "\nVariables:" syms.each do |sym| out << " #{sym}: #{@vars[sym].inspect}\n" end out end |
#set(var, value) ⇒ Object
35 36 37 |
# File 'lib/livetext/variables.rb', line 35 def set(var, value) @vars[var.to_sym] = value.to_s end |
#setvars(pairs) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/livetext/variables.rb', line 39 def setvars(pairs) pairs = pairs.to_a if pairs.is_a?(Hash) pairs.each do |var, value| api.setvar(var, value) end end |
#to_a ⇒ Object
46 47 48 |
# File 'lib/livetext/variables.rb', line 46 def to_a @vars.to_a end |