Class: MicrosoftKiotaSerializationJson::JsonParseNode
- Inherits:
-
Object
- Object
- MicrosoftKiotaSerializationJson::JsonParseNode
- Includes:
- MicrosoftKiotaAbstractions::ParseNode
- Defined in:
- lib/microsoft_kiota_serialization_json/json_parse_node.rb
Instance Method Summary collapse
- #assign_field_values(item) ⇒ Object
- #get_boolean_value ⇒ Object
- #get_child_node(name) ⇒ Object
- #get_collection_of_object_values(factory) ⇒ Object
- #get_collection_of_primitive_values(type) ⇒ Object
- #get_date_time_value ⇒ Object
- #get_date_value ⇒ Object
- #get_duration_value ⇒ Object
- #get_enum_value(type) ⇒ Object
- #get_enum_values(_type) ⇒ Object
- #get_float_value ⇒ Object
- #get_guid_value ⇒ Object
- #get_number_value ⇒ Object
- #get_object_value(factory) ⇒ Object
- #get_string_value ⇒ Object
- #get_time_value ⇒ Object
-
#initialize(node) ⇒ JsonParseNode
constructor
A new instance of JsonParseNode.
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
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/microsoft_kiota_serialization_json/json_parse_node.rb', line 102 def assign_field_values(item) fields = item.get_field_deserializers @current_node.each do |k, v| next if v.nil? 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_value ⇒ Object
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
128 129 130 131 132 |
# File 'lib/microsoft_kiota_serialization_json/json_parse_node.rb', line 128 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
83 84 85 86 87 88 89 90 91 |
# File 'lib/microsoft_kiota_serialization_json/json_parse_node.rb', line 83 def get_collection_of_object_values(factory) raise StandardError, 'Factory cannot be null' if factory.nil? @current_node.map do |object| next if object.nil? current_parse_node = JsonParseNode.new(object) 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 80 81 |
# File 'lib/microsoft_kiota_serialization_json/json_parse_node.rb', line 51 def get_collection_of_primitive_values(type) @current_node.map do |object| next if object.nil? current_parse_node = JsonParseNode.new(object) 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_value ⇒ Object
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_value ⇒ Object
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_value ⇒ Object
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
123 124 125 126 |
# File 'lib/microsoft_kiota_serialization_json/json_parse_node.rb', line 123 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
118 119 120 121 |
# File 'lib/microsoft_kiota_serialization_json/json_parse_node.rb', line 118 def get_enum_values(_type) raw_values = get_string_value raw_values.split(',').map(&:strip) end |
#get_float_value ⇒ Object
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_value ⇒ Object
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_value ⇒ Object
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
93 94 95 96 97 98 99 100 |
# File 'lib/microsoft_kiota_serialization_json/json_parse_node.rb', line 93 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_value ⇒ Object
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_value ⇒ Object
39 40 41 |
# File 'lib/microsoft_kiota_serialization_json/json_parse_node.rb', line 39 def get_time_value() Time.parse(@current_node) end |