Skip to content

Commit

Permalink
Clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed Apr 30, 2024
1 parent aaede38 commit 6b5e49f
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ RuboCop::RakeTask.new

require "yard"
YARD::Rake::YardocTask.new do |task|
task.files = ["lib/**/*.rb", "-", "LICENSE.md"]
task.files = ["lib/**/*.rb", "-", "LICENSE.md"]
task.options = [
"--no-private",
"--protected",
Expand Down
1 change: 1 addition & 0 deletions lib/multi_xml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

module MultiXml # rubocop:disable Metrics/ModuleLength
class ParseError < StandardError; end

class NoParserError < StandardError; end

class DisallowedTypeError < StandardError
Expand Down
8 changes: 4 additions & 4 deletions lib/multi_xml/parsers/libxml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ def parse(xml)

private

def each_child(node, &block)
node.each_child(&block)
def each_child(node, &)
node.each_child(&)
end

def each_attr(node, &block)
node.each_attr(&block)
def each_attr(node, &)
node.each_attr(&)
end

def node_name(node)
Expand Down
2 changes: 1 addition & 1 deletion lib/multi_xml/parsers/libxml2_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Libxml2Parser # :nodoc:
# hash::
# Hash to merge the converted element into.
def node_to_hash(node, hash = {}) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
node_hash = { MultiXml::CONTENT_ROOT => "" }
node_hash = {MultiXml::CONTENT_ROOT => ""}

name = node_name(node)

Expand Down
8 changes: 4 additions & 4 deletions lib/multi_xml/parsers/nokogiri.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ def parse(xml)

private

def each_child(node, &block)
node.children.each(&block)
def each_child(node, &)
node.children.each(&)
end

def each_attr(node, &block)
node.attribute_nodes.each(&block)
def each_attr(node, &)
node.attribute_nodes.each(&)
end

def node_name(node)
Expand Down
10 changes: 5 additions & 5 deletions lib/multi_xml/parsers/oga.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def parse(io)
end

def node_to_hash(node, hash = {}) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
node_hash = { MultiXml::CONTENT_ROOT => "" }
node_hash = {MultiXml::CONTENT_ROOT => ""}

name = node_name(node)

Expand Down Expand Up @@ -55,12 +55,12 @@ def node_to_hash(node, hash = {}) # rubocop:disable Metrics/AbcSize, Metrics/Cyc

private

def each_child(node, &block)
node.children.each(&block)
def each_child(node, &)
node.children.each(&)
end

def each_attr(node, &block)
node.attributes.each(&block)
def each_attr(node, &)
node.attributes.each(&)
end

def node_name(node)
Expand Down
16 changes: 8 additions & 8 deletions spec/parser_shared_example.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
@setting = MultiXml.parse(@xml, typecast_xml_value: false)["global_settings"]["group"]["setting"]
end

it { expect(@setting).to eq("type" => "string", "description" => { "__content__" => "Test" }) }
it { expect(@setting).to eq("type" => "string", "description" => {"__content__" => "Test"}) }
end
end

Expand All @@ -148,8 +148,8 @@

it "symbolizes keys" do
expect(MultiXml.parse(@xml,
symbolize_keys: true)).to eq(users: { user: [{ name: "Erik Michaels-Ober" },
{ name: "Wynn Netherland" }] })
symbolize_keys: true)).to eq(users: {user: [{name: "Erik Michaels-Ober"},
{name: "Wynn Netherland"}]})
end
end

Expand Down Expand Up @@ -332,7 +332,7 @@
it "returns the correctly parsed YAML when the type is allowed" do
expect(MultiXml.parse(@xml,
disallowed_types: [])["tag"]).to eq(:message => "Have a nice day", 1 => "returns an integer",
"array" => [{ "has-dashes" => true, "has_underscores" => true }])
"array" => [{"has-dashes" => true, "has_underscores" => true}])
end
end

Expand Down Expand Up @@ -672,7 +672,7 @@
end

it "parses correctly" do
expect(MultiXml.parse(@xml)).to eq("user" => { "name" => "Erik Michaels-Ober" })
expect(MultiXml.parse(@xml)).to eq("user" => {"name" => "Erik Michaels-Ober"})
end
end

Expand All @@ -683,8 +683,8 @@
end

it "parses correctly" do
expect(MultiXml.parse(@xml)).to eq("users" => { "user" => { "name" => "Erik Michaels-Ober",
"status" => { "text" => "Hello" } } })
expect(MultiXml.parse(@xml)).to eq("users" => {"user" => {"name" => "Erik Michaels-Ober",
"status" => {"text" => "Hello"}}})
end
end
end
Expand All @@ -699,7 +699,7 @@
end

it "parses correctly" do
expect(MultiXml.parse(@xml)).to eq("users" => { "user" => ["Erik Michaels-Ober", "Wynn Netherland"] })
expect(MultiXml.parse(@xml)).to eq("users" => {"user" => ["Erik Michaels-Ober", "Wynn Netherland"]})
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions spec/speed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
$iterations = 10

opts = OptionParser.new
opts.on("-v", "increase verbosity") { $verbose += 1 }
opts.on("-p", "--parser [String]", String, "parser to test") { |parsers| $parsers = [parsers] }
opts.on("-i", "--iterations [Int]", Integer, "iterations") { |iterations| $iterations = iterations }
opts.on("-h", "--help", "Show this display") do
opts.on("-v", "increase verbosity") { $verbose += 1 }
opts.on("-p", "--parser [String]", String, "parser to test") { |parsers| $parsers = [parsers] }
opts.on("-i", "--iterations [Int]", Integer, "iterations") { |iterations| $iterations = iterations }
opts.on("-h", "--help", "Show this display") do
puts opts
Process.exit!(0)
end
Expand Down

0 comments on commit 6b5e49f

Please sign in to comment.