Class: AbideDevUtils::Ppt::CodeIntrospection::Parameter

Inherits:
Object
  • Object
show all
Includes:
AbideDevUtils::Ppt::CodeGen::DataTypes
Defined in:
lib/abide_dev_utils/ppt/code_introspection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from AbideDevUtils::Ppt::CodeGen::DataTypes

#display_type_expr, #display_type_expr_with_entries, #display_type_expr_with_left_expr, #display_value, #infer_data_type

Constructor Details

#initialize(param_ast) ⇒ Parameter

Returns a new instance of Parameter.



49
50
51
# File 'lib/abide_dev_utils/ppt/code_introspection.rb', line 49

def initialize(param_ast)
  @ast = param_ast
end

Instance Attribute Details

#astObject (readonly)

Returns the value of attribute ast.



47
48
49
# File 'lib/abide_dev_utils/ppt/code_introspection.rb', line 47

def ast
  @ast
end

Instance Method Details

#name(raw: false) ⇒ Object



72
73
74
75
76
# File 'lib/abide_dev_utils/ppt/code_introspection.rb', line 72

def name(raw: false)
  return ast.name if raw

  "$#{ast.name}"
end

#to_a(raw: false) ⇒ Object



53
54
55
# File 'lib/abide_dev_utils/ppt/code_introspection.rb', line 53

def to_a(raw: false)
  [type_expr(raw: raw), name(raw: raw), value(raw: raw)]
end

#to_h(raw: false) ⇒ Object



57
58
59
60
61
62
63
# File 'lib/abide_dev_utils/ppt/code_introspection.rb', line 57

def to_h(raw: false)
  {
    type_expr: type_expr(raw: raw),
    name: name(raw: raw),
    value: value(raw: raw),
  }
end

#to_s(raw: false) ⇒ Object



65
66
67
68
69
70
# File 'lib/abide_dev_utils/ppt/code_introspection.rb', line 65

def to_s(raw: false)
  stra = [type_expr(raw: raw), name(raw: raw)]
  stra << '=' if value? && !raw
  stra << value(raw: raw)
  stra.compact.join(' ')
end

#type_expr(raw: false) ⇒ Object



93
94
95
96
97
98
# File 'lib/abide_dev_utils/ppt/code_introspection.rb', line 93

def type_expr(raw: false)
  return unless type_expr?
  return ast.type_expr if raw

  display_type_expr(ast)
end

#type_expr?Boolean

Returns:

  • (Boolean)


89
90
91
# File 'lib/abide_dev_utils/ppt/code_introspection.rb', line 89

def type_expr?
  ast.respond_to? :type_expr
end

#value(raw: false) ⇒ Object



82
83
84
85
86
87
# File 'lib/abide_dev_utils/ppt/code_introspection.rb', line 82

def value(raw: false)
  return unless value?
  return ast.value if raw

  display_value(ast)
end

#value?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/abide_dev_utils/ppt/code_introspection.rb', line 78

def value?
  ast.respond_to? :value
end