diff --git a/shard.yml b/shard.yml index d1eb65e..fd37f93 100644 --- a/shard.yml +++ b/shard.yml @@ -3,12 +3,12 @@ name: oq description: | A performant, and portable jq wrapper thats facilitates the consumption and output of formats other than JSON; using jq filters to transform the data. -version: 0.2.0 +version: 0.2.1 authors: - Blacksmoke16 -crystal: 0.29.0 +crystal: 0.30.0 license: MIT diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index ed47aa7..5bcdf27 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -1,5 +1,5 @@ name: oq -version: '0.2.0' +version: '0.2.1' summary: A performant, and portable jq wrapper to support formats other than JSON description: | A performant, and portable jq wrapper thats facilitates the consumption and output of formats other than JSON; using jq filters to transform the data. diff --git a/src/converters/xml.cr b/src/converters/xml.cr index 07ea27a..cd36516 100644 --- a/src/converters/xml.cr +++ b/src/converters/xml.cr @@ -17,7 +17,7 @@ module OQ::Converters::Xml loop do emit builder, json, xml_item: xml_item - break if json.kind == :EOF + break if json.kind.eof? end builder.end_element unless root.blank? @@ -36,10 +36,10 @@ module OQ::Converters::Xml private def self.emit(builder : XML::Builder, json : JSON::PullParser, key : String? = nil, array_key : String? = nil, *, xml_item : String) : Nil case json.kind - when :null then json.read_null - when :string, :int, :float, :bool then builder.text get_value json - when :begin_object then handle_object builder, json, key, array_key, xml_item: xml_item - when :begin_array then handle_array builder, json, key, array_key, xml_item: xml_item + when .null? then json.read_null + when .string?, .int?, .float?, .bool? then builder.text get_value json + when .begin_object? then handle_object builder, json, key, array_key, xml_item: xml_item + when .begin_array? then handle_array builder, json, key, array_key, xml_item: xml_item end end @@ -48,7 +48,7 @@ module OQ::Converters::Xml json.read_object do |k| if k.starts_with?('@') builder.attribute k.lchop('@'), get_value json - elsif json.kind == :begin_array || k == "#text" + elsif json.kind.begin_array? || k == "#text" emit builder, json, k, k, xml_item: xml_item else builder.element k do @@ -62,10 +62,10 @@ module OQ::Converters::Xml json.read_begin_array array_key = array_key || xml_item - if json.kind == :end_array + if json.kind.end_array? builder.element(array_key) { } unless @@at_root else - while json.kind != :end_array + until json.kind.end_array? builder.element array_key do emit builder, json, key, xml_item: xml_item end @@ -77,10 +77,10 @@ module OQ::Converters::Xml private def self.get_value(json : JSON::PullParser) : String case json.kind - when :string then json.read_string - when :int then json.read_int.to_s - when :float then json.read_float.to_s - when :bool then json.read_bool.to_s + when .string? then json.read_string + when .int? then json.read_int.to_s + when .float? then json.read_float.to_s + when .bool? then json.read_bool.to_s else "" end diff --git a/src/converters/yaml.cr b/src/converters/yaml.cr index 70b290e..821b780 100644 --- a/src/converters/yaml.cr +++ b/src/converters/yaml.cr @@ -1,10 +1,3 @@ -class JSON::Builder - def next_is_object_key? - state = @state.last - state.is_a?(ObjectState) && state.name - end -end - module OQ::Converters::Yaml # OPTIMIZE: Figure out a way to handle aliases/anchors while streaming. def self.deserialize(input : IO, output : IO, **args) : Nil @@ -20,29 +13,29 @@ module OQ::Converters::Yaml yaml.document do loop do case json.kind - when :null + when .null? yaml.scalar(nil) - when :bool + when .bool? yaml.scalar(json.bool_value) - when :int + when .int? yaml.scalar(json.int_value) - when :float + when .float? yaml.scalar(json.float_value) - when :string + when .string? if YAML::Schema::Core.reserved_string?(json.string_value) yaml.scalar(json.string_value, style: :double_quoted) else yaml.scalar(json.string_value) end - when :begin_array + when .begin_array? yaml.start_sequence - when :end_array + when .end_array? yaml.end_sequence - when :begin_object + when .begin_object? yaml.start_mapping - when :end_object + when .end_object? yaml.end_mapping - when :EOF + when .eof? break end json.read_next diff --git a/src/oq.cr b/src/oq.cr index b1c14d0..26b8489 100644 --- a/src/oq.cr +++ b/src/oq.cr @@ -6,7 +6,7 @@ require "./converters/*" # A performant and portable `jq` wrapper to support formats other than JSON. module OQ - VERSION = "0.2.0" + VERSION = "0.2.1" # The support formats that can be converted to/from. enum Format