Class: ActionView::RenderParser::RipperRenderParser::Node
- Inherits:
-
Array
- Object
- Array
- ActionView::RenderParser::RipperRenderParser::Node
show all
- Defined in:
- actionview/lib/action_view/render_parser/ripper_render_parser.rb
Overview
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Array
#as_json, #compact_blank!, #deep_dup, #excluding, #extract!, #extract_options!, #fifth, #forty_two, #fourth, #from, #in_groups, #in_groups_of, #including, #inquiry, #present?, #second, #second_to_last, #split, #third, #third_to_last, #to, #to_fs, #to_param, #to_query, #to_sentence, #to_xml, wrap
Constructor Details
#initialize(type, arr, opts = {}) ⇒ Node
Returns a new instance of Node.
9
10
11
12
|
# File 'actionview/lib/action_view/render_parser/ripper_render_parser.rb', line 9
def initialize(type, arr, opts = {})
@type = type
super(arr)
end
|
Instance Attribute Details
Returns the value of attribute type.
7
8
9
|
# File 'actionview/lib/action_view/render_parser/ripper_render_parser.rb', line 7
def type
@type
end
|
Instance Method Details
#argument_nodes ⇒ Object
33
34
35
36
37
38
39
40
41
|
# File 'actionview/lib/action_view/render_parser/ripper_render_parser.rb', line 33
def argument_nodes
raise unless fcall?
return [] if self[1].nil?
if self[1].last == false || self[1].last.type == :vcall
self[1][0...-1]
else
self[1][0..-1]
end
end
|
#call? ⇒ Boolean
55
56
57
|
# File 'actionview/lib/action_view/render_parser/ripper_render_parser.rb', line 55
def call?
type == :call
end
|
#call_method_name ⇒ Object
63
64
65
|
# File 'actionview/lib/action_view/render_parser/ripper_render_parser.rb', line 63
def call_method_name
self[2].first
end
|
14
15
16
|
# File 'actionview/lib/action_view/render_parser/ripper_render_parser.rb', line 14
def children
to_a
end
|
#fcall? ⇒ Boolean
23
24
25
|
# File 'actionview/lib/action_view/render_parser/ripper_render_parser.rb', line 23
def fcall?
type == :command || type == :fcall
end
|
#fcall_named?(name) ⇒ Boolean
27
28
29
30
31
|
# File 'actionview/lib/action_view/render_parser/ripper_render_parser.rb', line 27
def fcall_named?(name)
fcall? &&
self[0].type == :@ident &&
self[0][0] == name
end
|
#hash? ⇒ Boolean
81
82
83
|
# File 'actionview/lib/action_view/render_parser/ripper_render_parser.rb', line 81
def hash?
type == :bare_assoc_hash || type == :hash
end
|
#hash_from_body(body) ⇒ Object
95
96
97
98
99
100
101
|
# File 'actionview/lib/action_view/render_parser/ripper_render_parser.rb', line 95
def hash_from_body(body)
body.to_h do |hash_node|
return nil if hash_node.type != :assoc_new
[hash_node[0], hash_node[1]]
end
end
|
18
19
20
21
|
# File 'actionview/lib/action_view/render_parser/ripper_render_parser.rb', line 18
def inspect
typeinfo = type && type != :list ? ":" + type.to_s + ", " : ""
"s(" + typeinfo + map(&:inspect).join(", ") + ")"
end
|
#string? ⇒ Boolean
43
44
45
|
# File 'actionview/lib/action_view/render_parser/ripper_render_parser.rb', line 43
def string?
type == :string_literal
end
|
#symbol? ⇒ Boolean
103
104
105
|
# File 'actionview/lib/action_view/render_parser/ripper_render_parser.rb', line 103
def symbol?
type == :@label || type == :symbol_literal
end
|
85
86
87
88
89
90
91
92
93
|
# File 'actionview/lib/action_view/render_parser/ripper_render_parser.rb', line 85
def to_hash
if type == :bare_assoc_hash
hash_from_body(self[0])
elsif type == :hash && self[0] == nil
{}
elsif type == :hash && self[0].type == :assoclist_from_args
hash_from_body(self[0][0])
end
end
|
#to_string ⇒ Object
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'actionview/lib/action_view/render_parser/ripper_render_parser.rb', line 67
def to_string
raise unless string?
self[0].map do |node|
case node.type
when :@tstring_content
node[0]
when :string_embexpr
"*"
end
end.join("")
end
|
#to_symbol ⇒ Object
107
108
109
110
111
112
113
114
115
|
# File 'actionview/lib/action_view/render_parser/ripper_render_parser.rb', line 107
def to_symbol
if type == :@label && self[0] =~ /\A(.+):\z/
$1.to_sym
elsif type == :symbol_literal && self[0].type == :symbol && self[0][0].type == :@ident
self[0][0][0].to_sym
else
raise "not a symbol?: #{self.inspect}"
end
end
|
#variable_name ⇒ Object
59
60
61
|
# File 'actionview/lib/action_view/render_parser/ripper_render_parser.rb', line 59
def variable_name
self[0][0]
end
|
#variable_reference? ⇒ Boolean
47
48
49
|
# File 'actionview/lib/action_view/render_parser/ripper_render_parser.rb', line 47
def variable_reference?
type == :var_ref
end
|
#vcall? ⇒ Boolean
51
52
53
|
# File 'actionview/lib/action_view/render_parser/ripper_render_parser.rb', line 51
def vcall?
type == :vcall
end
|