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.



62
63
64
# File 'lib/abide_dev_utils/ppt/code_introspection.rb', line 62

def initialize(param_ast)
  @ast = param_ast
end

Instance Attribute Details

#astObject (readonly)

Returns the value of attribute ast.



60
61
62
# File 'lib/abide_dev_utils/ppt/code_introspection.rb', line 60

def ast
  @ast
end

Instance Method Details

#name(raw: false) ⇒ Object



85
86
87
88
89
# File 'lib/abide_dev_utils/ppt/code_introspection.rb', line 85

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

  "$#{ast.name}"
end

#to_a(raw: false) ⇒ Object



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

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

#to_h(raw: false) ⇒ Object



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

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



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

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



106
107
108
109
110
111
# File 'lib/abide_dev_utils/ppt/code_introspection.rb', line 106

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)


102
103
104
# File 'lib/abide_dev_utils/ppt/code_introspection.rb', line 102

def type_expr?
  ast.respond_to? :type_expr
end

#value(raw: false) ⇒ Object



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

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

  display_value(ast)
end

#value?Boolean

Returns:

  • (Boolean)


91
92
93
# File 'lib/abide_dev_utils/ppt/code_introspection.rb', line 91

def value?
  ast.respond_to? :value
end