Class: Rasm::Ref

Inherits:
Object
  • Object
show all
Defined in:
lib/rasm/ref.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scope, selector, options = {}) ⇒ Ref

Returns a new instance of Ref.



5
6
7
8
9
# File 'lib/rasm/ref.rb', line 5

def initialize(scope, selector, options = {})
  @scope = scope
  @selector = selector
  @options = options
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



47
48
49
50
# File 'lib/rasm/ref.rb', line 47

def method_missing(method, *args)
  return data[method] if args.empty? && data.include?(method)
  super
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/rasm/ref.rb', line 4

def options
  @options
end

#scopeObject (readonly)

Returns the value of attribute scope.



4
5
6
# File 'lib/rasm/ref.rb', line 4

def scope
  @scope
end

#selectorObject (readonly)

Returns the value of attribute selector.



4
5
6
# File 'lib/rasm/ref.rb', line 4

def selector
  @selector
end

Instance Method Details

#[](key) ⇒ Object



16
17
18
# File 'lib/rasm/ref.rb', line 16

def [](key)
  data[key]
end

#[]=(key, value) ⇒ Object



20
21
22
# File 'lib/rasm/ref.rb', line 20

def []=(key, value)
  data[key] = value
end

#bind(defs) ⇒ Object



11
12
13
14
# File 'lib/rasm/ref.rb', line 11

def bind(defs)
  data.merge!(defs)
  self
end

#respond_to_missing?(method) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/rasm/ref.rb', line 43

def respond_to_missing?(method, *)
  data.include?(method) || super
end

#to_sObject



24
25
26
27
28
29
30
31
32
# 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

#valObject



34
35
36
37
38
39
40
41
# 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