Module: CodeBreaker::Parsable::DataTypes

Includes:
Node
Included in:
CodeBreaker::Parser
Defined in:
lib/code_breaker/parsable/data_types.rb

Instance Method Summary collapse

Methods included from Node

#method_missing, #not_implemented_message, #parse, #parse_as_hash, #parse_as_last_child_hash, #parse_as_node_type, #parse_children

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class CodeBreaker::Parsable::Node

Instance Method Details

#parse_dstr_node(node) ⇒ Object

interpolated string



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/code_breaker/parsable/data_types.rb', line 28

def parse_dstr_node(node)
  values = parse_as_hash(node)[node.type].map do |value|
    if value.is_a?(Array)
      value.flatten(1)
    else
      value
    end
  end

  { node.type => values }
end

#parse_false_node(node) ⇒ Object



14
15
16
# File 'lib/code_breaker/parsable/data_types.rb', line 14

def parse_false_node(node)
  FalseClass
end

#parse_float_node(node) ⇒ Object



44
45
46
# File 'lib/code_breaker/parsable/data_types.rb', line 44

def parse_float_node(node)
  Float
end

#parse_int_node(node) ⇒ Object



52
53
54
# File 'lib/code_breaker/parsable/data_types.rb', line 52

def parse_int_node(node)
  node.children[0].class
end

#parse_nil_node(node) ⇒ Object



6
7
8
# File 'lib/code_breaker/parsable/data_types.rb', line 6

def parse_nil_node(node)
  NilClass
end

#parse_pair_node(node) ⇒ Object



56
57
58
# File 'lib/code_breaker/parsable/data_types.rb', line 56

def parse_pair_node(node)
  { parse(node.children[0]) => parse(node.children[1]) }
end

#parse_regexp_node(node) ⇒ Object



48
49
50
# File 'lib/code_breaker/parsable/data_types.rb', line 48

def parse_regexp_node(node)
  Regexp
end

#parse_str_node(node) ⇒ Object



18
19
20
# File 'lib/code_breaker/parsable/data_types.rb', line 18

def parse_str_node(node)
  String
end

#parse_sym_node(node) ⇒ Object



40
41
42
# File 'lib/code_breaker/parsable/data_types.rb', line 40

def parse_sym_node(node)
  Symbol
end

#parse_true_node(node) ⇒ Object



10
11
12
# File 'lib/code_breaker/parsable/data_types.rb', line 10

def parse_true_node(node)
  TrueClass
end

#parse_xstr_node(node) ⇒ Object

interpolated executed string



23
24
25
# File 'lib/code_breaker/parsable/data_types.rb', line 23

def parse_xstr_node(node)
  { node.type => parse_children(node).first }
end