Class: Alf::Types::Selector
- Inherits:
-
Object
- Object
- Alf::Types::Selector
- Defined in:
- lib/alf/types/selector.rb
Instance Method Summary collapse
- #composite? ⇒ Boolean
- #dive(attr) ⇒ Object
- #outcoerce ⇒ Object
- #select(tuple) ⇒ Object
- #simple? ⇒ Boolean
- #to_a ⇒ Object
- #to_lispy ⇒ Object
- #to_ruby_literal ⇒ Object (also: #to_s, #inspect)
Instance Method Details
#composite? ⇒ Boolean
22 23 24 |
# File 'lib/alf/types/selector.rb', line 22 def composite? !simple? end |
#dive(attr) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/alf/types/selector.rb', line 35 def dive(attr) components = to_a return nil unless (components.first == attr) && components.size > 1 rest = components[1..-1] Selector.new(rest.size == 1 ? rest.first : rest) end |
#outcoerce ⇒ Object
26 27 28 |
# File 'lib/alf/types/selector.rb', line 26 def outcoerce reused_instance end |
#select(tuple) ⇒ Object
30 31 32 33 |
# File 'lib/alf/types/selector.rb', line 30 def select(tuple) return tuple[reused_instance] unless reused_instance.is_a?(Array) reused_instance.inject(tuple){|t,a| t && t[a] } end |
#simple? ⇒ Boolean
18 19 20 |
# File 'lib/alf/types/selector.rb', line 18 def simple? reused_instance.is_a?(Symbol) end |
#to_a ⇒ Object
42 43 44 |
# File 'lib/alf/types/selector.rb', line 42 def to_a Array(reused_instance) end |
#to_lispy ⇒ Object
46 47 48 |
# File 'lib/alf/types/selector.rb', line 46 def to_lispy Support.to_ruby_literal(reused_instance) end |
#to_ruby_literal ⇒ Object Also known as: to_s, inspect
50 51 52 |
# File 'lib/alf/types/selector.rb', line 50 def to_ruby_literal "Alf::Selector[#{Support.to_ruby_literal(reused_instance)}]" end |