Class: ActionviewPrecompiler::ASTParser::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/actionview_precompiler/ast_parser/jruby.rb,
lib/actionview_precompiler/ast_parser/ruby26.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node) ⇒ Node

Returns a new instance of Node.



12
13
14
# File 'lib/actionview_precompiler/ast_parser/jruby.rb', line 12

def initialize(node)
  @node = node
end

Class Method Details

.wrap(node) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/actionview_precompiler/ast_parser/jruby.rb', line 4

def self.wrap(node)
  if org::jruby::ast::Node === node
    new(node)
  else
    node
  end
end

Instance Method Details

#argument_nodesObject



28
29
30
31
32
# File 'lib/actionview_precompiler/ast_parser/jruby.rb', line 28

def argument_nodes
  @node.args_node.to_a[0...@node.args_node.size].map do |arg|
    self.class.wrap(arg)
  end
end

#array?Boolean

Returns:

  • (Boolean)


22
# File 'lib/actionview_precompiler/ast_parser/jruby.rb', line 22

def array?;  org::jruby::ast::ArrayNode  === @node; end

#childrenObject



16
17
18
19
20
# File 'lib/actionview_precompiler/ast_parser/jruby.rb', line 16

def children
  @children ||= @node.child_nodes.map do |child|
    self.class.wrap(child)
  end
end

#fcall?Boolean

Returns:

  • (Boolean)


23
# File 'lib/actionview_precompiler/ast_parser/jruby.rb', line 23

def fcall?;  org::jruby::ast::FCallNode  === @node; end

#fcall_named?(name) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
51
52
53
# File 'lib/actionview_precompiler/ast_parser/jruby.rb', line 48

def fcall_named?(name)
  fcall? &&
    @node.name == name &&
    @node.args_node &&
    org::jruby::ast::ArrayNode === @node.args_node
end

#hash?Boolean

Returns:

  • (Boolean)


24
# File 'lib/actionview_precompiler/ast_parser/jruby.rb', line 24

def hash?;   org::jruby::ast::HashNode   === @node; end

#inspectObject



22
23
24
# File 'lib/actionview_precompiler/ast_parser/ruby26.rb', line 22

def inspect
  "#<#{self.class} #{@node.inspect}>"
end

#string?Boolean

Returns:

  • (Boolean)


25
# File 'lib/actionview_precompiler/ast_parser/jruby.rb', line 25

def string?; org::jruby::ast::StrNode    === @node; end

#symbol?Boolean

Returns:

  • (Boolean)


26
# File 'lib/actionview_precompiler/ast_parser/jruby.rb', line 26

def symbol?; org::jruby::ast::SymbolNode === @node; end

#to_hashObject



34
35
36
37
38
# File 'lib/actionview_precompiler/ast_parser/jruby.rb', line 34

def to_hash
  @node.pairs.each_with_object({}) do |pair, object|
    object[self.class.wrap(pair.key)] = self.class.wrap(pair.value)
  end
end

#to_stringObject



40
41
42
# File 'lib/actionview_precompiler/ast_parser/jruby.rb', line 40

def to_string
  @node.value
end

#to_symbolObject



44
45
46
# File 'lib/actionview_precompiler/ast_parser/jruby.rb', line 44

def to_symbol
  @node.name
end