class Rasm::Ref

Attributes

options[R]
scope[R]
selector[R]

Public Class Methods

new(scope, selector, options = {}) click to toggle source
# File lib/rasm/ref.rb, line 5
def initialize(scope, selector, options = {})
  @scope = scope
  @selector = selector
  @options = options
end

Public Instance Methods

[](key) click to toggle source
# File lib/rasm/ref.rb, line 16
def [](key)
  data[key]
end
[]=(key, value) click to toggle source
# File lib/rasm/ref.rb, line 20
def []=(key, value)
  data[key] = value
end
bind(defs) click to toggle source
# File lib/rasm/ref.rb, line 11
def bind(defs)
  data.merge!(defs)
  self
end
method_missing(method, *args) click to toggle source
Calls superclass method
# File lib/rasm/ref.rb, line 47
def method_missing(method, *args)
  return data[method] if args.empty? && data.include?(method)
  super
end
respond_to_missing?(method, *) click to toggle source
Calls superclass method
# File lib/rasm/ref.rb, line 43
def respond_to_missing?(method, *)
  data.include?(method) || super
end
to_s() click to toggle source
# File lib/rasm/ref.rb, line 24
def to_s
  prefix = options[:prefix] || '#'
  if selector.is_a? Array
    split = options[:split] || ':'
    selector.map{|item| "#{prefix}#{item}"}.join(split)
  else
    "#{prefix}#{selector}"
  end
end
val() click to toggle source
# File lib/rasm/ref.rb, line 34
def val
  split = options[:split] || ':'
  if selector.respond_to? :map
    selector.map{|item| find(scope, item) }.join(split)
  else
    find(scope, selector)
  end
end

Private Instance Methods

data() click to toggle source
# File lib/rasm/ref.rb, line 53
def data
   @data ||= {}
end
find(scope, selector) click to toggle source
# File lib/rasm/ref.rb, line 57
def find(scope, selector)
  value = scope[selector]
  value.respond_to?(:val) ? value.val : value
end