Skip to content

Commit

Permalink
created module Electretri::API
Browse files Browse the repository at this point in the history
  • Loading branch information
imbrito committed Apr 2, 2018
1 parent 86a920e commit 8b5f309
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 19 deletions.
13 changes: 1 addition & 12 deletions lib/electretri.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,5 @@
require "json"

module Electretri
def self.load_yml(path)
YAML.load_file(path)
end

def self.load_json(path)
JSON.parse(File.read(path))
end

def self.load_xml(path)
Hash.from_xml(File.read(path))["hash"]
end

autoload :API, 'electretri/api'
end
23 changes: 23 additions & 0 deletions lib/electretri/api.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require "active_support"
require "active_support/core_ext"
require "builder"
require "yaml"
require "json"

module Electretri
module API
class << self
def load_yml(path)
YAML.load_file(path)
end

def load_json(path)
JSON.parse(File.read(path))
end

def load_xml(path)
Hash.from_xml(File.read(path))["hash"]
end
end
end
end
4 changes: 2 additions & 2 deletions spec/json_spec.rb → spec/api/json_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require "spec_helper"

RSpec.describe Electretri do
RSpec.describe Electretri::API do

let(:by_json) { Electretri.load_json(electretri_json) }
let(:by_json) { Electretri::API.load_json(electretri_json) }

context "load_json" do
it "returns hash" do
Expand Down
4 changes: 2 additions & 2 deletions spec/xml_spec.rb → spec/api/xml_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require "spec_helper"

RSpec.describe Electretri do
RSpec.describe Electretri::API do

let(:by_xml) { Electretri.load_xml(electretri_xml) }
let(:by_xml) { Electretri::API.load_xml(electretri_xml) }

context "load_xml" do
it "returns hash" do
Expand Down
4 changes: 2 additions & 2 deletions spec/yml_spec.rb → spec/api/yml_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require "spec_helper"

RSpec.describe Electretri do
RSpec.describe Electretri::API do

let(:by_yml) { Electretri.load_yml(electretri_yml) }
let(:by_yml) { Electretri::API.load_yml(electretri_yml) }

context "load_yml" do
it "returns hash" do
Expand Down
2 changes: 1 addition & 1 deletion spec/electretri_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "spec_helper"

RSpec.describe Electretri do
RSpec.describe Electretri::VERSION do

it "has a version number" do
expect(Electretri::VERSION).not_to be nil
Expand Down

0 comments on commit 8b5f309

Please sign in to comment.