Class: MicrosoftKiotaSerializationJson::JsonParseNode

Inherits:
Object
  • Object
show all
Includes:
MicrosoftKiotaAbstractions::ParseNode
Defined in:
lib/microsoft_kiota_serialization_json/json_parse_node.rb

Instance Method Summary collapse

Constructor Details

#initialize(node) ⇒ JsonParseNode

Returns a new instance of JsonParseNode.



11
12
13
# File 'lib/microsoft_kiota_serialization_json/json_parse_node.rb', line 11

def initialize(node)
  @current_node = node
end

Instance Method Details

#assign_field_values(item) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/microsoft_kiota_serialization_json/json_parse_node.rb', line 98

def assign_field_values(item)
  fields = item.get_field_deserializers
  @current_node.each do |k, v|
    deserializer = fields[k]
    if deserializer
      deserializer.call(JsonParseNode.new(v))
    elsif item.additional_data
      item.additional_data[k] = v
    else
      item.additional_data = Hash.new(k => v)
    end
  end
end

#get_boolean_valueObject



19
20
21
# File 'lib/microsoft_kiota_serialization_json/json_parse_node.rb', line 19

def get_boolean_value
  @current_node
end

#get_child_node(name) ⇒ Object

Raises:

  • (StandardError)


122
123
124
125
126
# File 'lib/microsoft_kiota_serialization_json/json_parse_node.rb', line 122

def get_child_node(name)
  raise StandardError, 'Name cannot be null' if name.nil? || name.empty?
  raw_value = @current_node[name]
  return JsonParseNode.new(raw_value) if raw_value
end

#get_collection_of_object_values(factory) ⇒ Object

Raises:

  • (StandardError)


81
82
83
84
85
86
87
# File 'lib/microsoft_kiota_serialization_json/json_parse_node.rb', line 81

def get_collection_of_object_values(factory)
  raise StandardError, 'Factory cannot be null' if factory.nil?
  @current_node.map do |x|
    current_parse_node = JsonParseNode.new(x)
    current_parse_node.get_object_value(factory)
  end
end

#get_collection_of_primitive_values(type) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/microsoft_kiota_serialization_json/json_parse_node.rb', line 51

def get_collection_of_primitive_values(type)
  @current_node.map do |x|
    current_parse_node = JsonParseNode.new(x)
    case type
    when String
      current_parse_node.get_string_value
    when Float
      current_parse_node.get_float_value
    when Integer
      current_parse_node.get_float_value
    when "Boolean"
      current_parse_node.get_float_value
    when DateTime
      current_parse_node.get_date_time_value
    when Time
      current_parse_node.get_time_value
    when Date 
      current_parse_node.get_date_value 
    when MicrosoftKiotaAbstractions::ISODuration
      current_parse_node.get_duration_value
    when UUIDTools::UUID
      current_parse_node.get_guid_value
    else
      current_parse_node.get_string_value
    end
  rescue StandardError => e
    raise e.class, `Failed to fetch #{type} type`
  end
end

#get_date_time_valueObject



43
44
45
# File 'lib/microsoft_kiota_serialization_json/json_parse_node.rb', line 43

def get_date_time_value()
  DateTime.parse(@current_node)
end

#get_date_valueObject



35
36
37
# File 'lib/microsoft_kiota_serialization_json/json_parse_node.rb', line 35

def get_date_value
  Date.parse(@current_node)
end

#get_duration_valueObject



47
48
49
# File 'lib/microsoft_kiota_serialization_json/json_parse_node.rb', line 47

def get_duration_value()
  MicrosoftKiotaAbstractions::ISODuration.new(@current_node)
end

#get_enum_value(type) ⇒ Object



117
118
119
120
# File 'lib/microsoft_kiota_serialization_json/json_parse_node.rb', line 117

def get_enum_value(type)
  items = get_enum_values(type).map(&:to_sym)
  items[0] if items.length.positive?
end

#get_enum_values(_type) ⇒ Object



112
113
114
115
# File 'lib/microsoft_kiota_serialization_json/json_parse_node.rb', line 112

def get_enum_values(_type)
  raw_values = get_string_value
  raw_values.split(',').map(&:strip)
end

#get_float_valueObject



27
28
29
# File 'lib/microsoft_kiota_serialization_json/json_parse_node.rb', line 27

def get_float_value
  @current_node.to_f
end

#get_guid_valueObject



31
32
33
# File 'lib/microsoft_kiota_serialization_json/json_parse_node.rb', line 31

def get_guid_value
  UUIDTools::UUID.parse(@current_node)
end

#get_number_valueObject



23
24
25
# File 'lib/microsoft_kiota_serialization_json/json_parse_node.rb', line 23

def get_number_value
  @current_node.to_i
end

#get_object_value(factory) ⇒ Object



89
90
91
92
93
94
95
96
# File 'lib/microsoft_kiota_serialization_json/json_parse_node.rb', line 89

def get_object_value(factory)
  raise StandardError, 'Factory cannot be null' if factory.nil?
  item = factory.call(self)
  assign_field_values(item)
  item
rescue StandardError => e
  raise e.class, 'Error during deserialization'
end

#get_string_valueObject



15
16
17
# File 'lib/microsoft_kiota_serialization_json/json_parse_node.rb', line 15

def get_string_value
  @current_node.to_s
end

#get_time_valueObject



39
40
41
# File 'lib/microsoft_kiota_serialization_json/json_parse_node.rb', line 39

def get_time_value()
  Time.parse(@current_node)
end