Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static Data Export stuff #41

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,7 @@ Issue reports and pull requests are welcome on GitHub at https://github.com/biow

* Add `EveOnline::AccountTypeObject` class for handling EveOnline account type values
* `EveOnline::Account::ApiKeyInfo#type` now returns symbols. e.g. `:account`
* Add `EveOnline::SDE::TypeID` for handling TypeIDs for SDE

**v0.9.0**

Expand Down
5 changes: 5 additions & 0 deletions lib/eve_online.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,10 @@

require 'eve_online/sovereignty/campaigns'

require 'eve_online/sde/type_ids'
require 'eve_online/sde/type_id'
require 'eve_online/sde/blueprints'
require 'eve_online/sde/blueprint'

module EveOnline
end
31 changes: 31 additions & 0 deletions lib/eve_online/sde/blueprint.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module EveOnline
module SDE
class Blueprint
attr_reader :options

def initialize(options)
@options = options
end

def as_json
{
type_id: type_id,
max_production_limit: max_production_limit,
activities: activities
}
end

def type_id
options.fetch('blueprintTypeID')
end

def max_production_limit
options.fetch('maxProductionLimit')
end

def activities
options.fetch('activities')
end
end
end
end
30 changes: 30 additions & 0 deletions lib/eve_online/sde/blueprints.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
require 'yaml'
require 'memoist'

module EveOnline
module SDE
class Blueprints
extend Memoist

attr_reader :file

def initialize(file)
@file = file
end

def blueprints
output = []
content.each do |entry|
output << Blueprint.new(entry.last)
end
output
end
memoize :blueprints

def content
YAML.load(File.open(file))
end
memoize :content
end
end
end
26 changes: 26 additions & 0 deletions lib/eve_online/sde/type_id.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module EveOnline
module SDE
class TypeID
attr_reader :options

def initialize(options)
@options = options
end

def as_json
{
type_id: type_id,
data: data
}
end

def type_id
@type_id ||= options.first
end

def data
@data ||= options.last
end
end
end
end
25 changes: 25 additions & 0 deletions lib/eve_online/sde/type_ids.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module EveOnline
module SDE
class TypeIDs
attr_reader :file

def initialize(file)
@file = file
end

def type_ids
@type_ids ||= begin
output = []
content.each do |entry|
output << TypeID.new(entry)
end
output
end
end

def content
@content ||= YAML.load(File.open(file))
end
end
end
end
71 changes: 71 additions & 0 deletions spec/eve_online/sde/blueprint_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
require 'spec_helper'

describe EveOnline::SDE::Blueprint do
describe '#initialize' do
let(:options) { double }

subject { described_class.new(options) }

its(:options) { should eq(options) }
end

describe '#as_json' do
let(:options) { double }

let(:activities) { double }

let(:blueprint) { described_class.new(options) }

before { expect(blueprint).to receive(:type_id).and_return(681) }

before { expect(blueprint).to receive(:max_production_limit).and_return(300) }

before { expect(blueprint).to receive(:activities).and_return(activities) }

subject { blueprint.as_json }

its([:type_id]) { should eq(681) }

its([:max_production_limit]) { should eq(300) }

its([:activities]) { should eq(activities) }
end

describe '#type_id' do
let(:options) { double }

subject { described_class.new(options) }

before do
#
# subject.options.fetch('blueprintTypeID')
#
expect(subject).to receive(:options) do
double.tap do |a|
expect(a).to receive(:fetch).with('blueprintTypeID')
end
end
end

specify { expect { subject.type_id }.not_to raise_error }
end

describe '#max_production_limit' do
let(:options) { double }

subject { described_class.new(options) }

before do
#
# subject.options.fetch('maxProductionLimit')
#
expect(subject).to receive(:options) do
double.tap do |a|
expect(a).to receive(:fetch).with('maxProductionLimit')
end
end
end

specify { expect { subject.max_production_limit }.not_to raise_error }
end
end
11 changes: 11 additions & 0 deletions spec/eve_online/sde/blueprints_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require 'spec_helper'

describe EveOnline::SDE::Blueprints do
describe '#initialize' do
let(:file) { double }

subject { described_class.new(file) }

its(:file) { should eq(file) }
end
end
83 changes: 83 additions & 0 deletions spec/eve_online/sde/type_id_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# encoding: utf-8
require 'spec_helper'

describe EveOnline::SDE::TypeID do
describe '#initialize' do
let(:options) { double }

subject { described_class.new(options) }

its(:options) { should eq(options) }
end

describe '#as_json' do
let(:options) { double }

let(:type_id) { described_class.new(options) }

let(:data) do
{
'groupID' => 0,
'mass' => 1.0,
'name' => {
'de' => '#System',
'en' => '#System',
'fr' => '#Système',
'ja' => '"#システム',
'ru' => '#Система',
'zh' => '#星系'
},
'portionSize' => 1,
'published' => false
}
end

before { expect(type_id).to receive(:type_id).and_return(0) }

before { expect(type_id).to receive(:data).and_return(data) }

subject { type_id.as_json }

its([:type_id]) { should eq(0) }

its([:data]) { should eq(data) }
end

describe '#type_id' do
let(:options) { double }

subject { described_class.new(options) }

before do
#
# subject.options.first
#
expect(subject).to receive(:options) do
double.tap do |a|
expect(a).to receive(:first)
end
end
end

specify { expect { subject.type_id }.not_to raise_error }
end

describe '#data' do
let(:options) { double }

subject { described_class.new(options) }

before do
#
# subject.options.last
#
expect(subject).to receive(:options) do
double.tap do |a|
expect(a).to receive(:last)
end
end
end

specify { expect { subject.data }.not_to raise_error }
end
end