Class: VectorSpace::ComponentReflection

Inherits:
Object
  • Object
show all
Defined in:
lib/vector_space/component_reflection.rb

Direct Known Subclasses

DimensionReflection, IndexReflection

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(component, options = {}) ⇒ ComponentReflection

Returns a new instance of ComponentReflection.



3
4
5
# File 'lib/vector_space/component_reflection.rb', line 3

def initialize(component, options = {})
  @component, @options = component, options
end

Instance Attribute Details

#componentObject (readonly)

Returns the value of attribute component.



11
12
13
# File 'lib/vector_space/component_reflection.rb', line 11

def component
  @component
end

#optionsObject (readonly)

Returns the value of attribute options.



11
12
13
# File 'lib/vector_space/component_reflection.rb', line 11

def options
  @options
end

Instance Method Details

#getterObject



13
14
15
# File 'lib/vector_space/component_reflection.rb', line 13

def getter
  options[:getter] || component.to_sym
end

#to_sObject



7
8
9
# File 'lib/vector_space/component_reflection.rb', line 7

def to_s
  "#{component} component (#{default.class})"
end

#value(value) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/vector_space/component_reflection.rb', line 17

def value(value)
  value ||= default

  if options[:coerce]
    options[:coerce].to_proc.call(value)
  else
    value
  end
end