reccore 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ OGUzOTEyMWFkY2Q4ODliODY1OWVmNjc1NzgwMjczY2FiNTdjZjk0YQ==
5
+ data.tar.gz: !binary |-
6
+ YzFkMDMwZDdmOGY2YjU1OTg2YjJlMTIxYjRjM2QzMzY4NzcxYjdjNQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ OGQwZDYxMzE1NDUxMTRjY2I1YmM5MmZiZWUyNWZlNjEyN2VmZjY3NGU2YThl
10
+ YzNjN2VlMTEyNmE2OTZiNmMxZGM5YmJjZjRiMzEzZTBjZTBmM2U0NWRkYzk4
11
+ MjJjODczMTNjZGYzYWNjMGUxYjU0ODQ2NWRlNmU2NmJmM2NkZDc=
12
+ data.tar.gz: !binary |-
13
+ OWU4OGE2NmY3NmI3ODZmNzA3M2ZiOTRkOWY5ZjJlZDdkNzY0ZjIyNzEyZTM0
14
+ MGY2MDY0ZDg3Y2E2NDk1ZmY3MGE4NWRiMDZlNjIxMWVmZGI0MDNkMjFlZmUw
15
+ ZTZmNDk0YjU0Mjk5NmZiZjBlZDcxYjIxZjgzZDIyNmYwN2U4ZmQ=
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .coveralls.yml
data/.rubocop.yml ADDED
@@ -0,0 +1,60 @@
1
+ Lint/HandleExceptions:
2
+ Enabled: false
3
+
4
+ Metrics/BlockNesting:
5
+ Max: 2
6
+
7
+ Metrics/LineLength:
8
+ AllowURI: true
9
+ Enabled: false
10
+
11
+ Metrics/MethodLength:
12
+ CountComments: false
13
+ Max: 15
14
+
15
+ Metrics/ParameterLists:
16
+ Max: 4
17
+ CountKeywordArgs: true
18
+
19
+ Metrics/AbcSize:
20
+ Enabled: false
21
+
22
+ Style/AccessModifierIndentation:
23
+ EnforcedStyle: outdent
24
+
25
+ Style/CollectionMethods:
26
+ PreferredMethods:
27
+ map: 'collect'
28
+ reduce: 'inject'
29
+ find: 'detect'
30
+ find_all: 'select'
31
+
32
+ Style/Documentation:
33
+ Enabled: false
34
+
35
+ Style/DotPosition:
36
+ EnforcedStyle: trailing
37
+
38
+ Style/DoubleNegation:
39
+ Enabled: false
40
+
41
+ Style/EachWithObject:
42
+ Enabled: false
43
+
44
+ Style/Encoding:
45
+ Enabled: false
46
+
47
+ Style/HashSyntax:
48
+ EnforcedStyle: hash_rockets
49
+
50
+ Style/Lambda:
51
+ Enabled: false
52
+
53
+ Style/RaiseArgs:
54
+ EnforcedStyle: exploded
55
+
56
+ Style/SpaceInsideHashLiteralBraces:
57
+ EnforcedStyle: no_space
58
+
59
+ Style/TrailingComma:
60
+ EnforcedStyleForMultiline: 'comma'
data/.travis.yml ADDED
@@ -0,0 +1,15 @@
1
+ bundler_args: "--without development"
2
+ cache: bundler
3
+ gemfile:
4
+ - Gemfile
5
+ language: ruby
6
+ rvm:
7
+ - 2.2.2
8
+ deploy:
9
+ provider: rubygems
10
+ api_key:
11
+ secure: AogCDSw8k8KPcYKFhklrPlb9fw7pH6y1UUr4KUhSb2uN/ckbtB13uMHErxfUxYppar7lfXVmKHdK3rRrTya9lXJVfznzh5alYNzs6At/K38AxDjEzgGssIffepznS3NBnPiQFgUFysuNUisRrK/hVN72z5GqsbCtXhv40VjJdyygl0iEeOr2ggQDkGaSvEXTTg7SVbga0Uodjl6hTX/i2SNipJYwHRfEn9QmwEPcPHPy3KReh/AlpIZ7XBtp/uiEp7qPwuSMHvuJrFElUFifj8oR8k6f0MfDptB91rwKodXgCjvjREWAoYyBxwYHRXVRgvLn7Bqr7eP4UVfi4Iiggj4sxnwocVvICrmRT3qExg/itOKcgVt1IM0gLD5mFVP4FANvvqf+hg1OMuOwyqvpuTWPy2L3IHntNHA2C3RFG5BgckBIBtnlngkrixduhDDtXRciHGBSHICAK04nS3sU4FhYYmL/BJk+y880rfJ0ZKJDRTL3qNN8mTqEYsXWwXr8eCuS7k23Thv/80ddYWwY3HcgcMvBzt3uXfRuvO5/vnZRXUmMFFHv1nVUDiM8YFBpOt4cimFtEcmv3dut5cPj9ur9IDiKjfYX0pBcGsDYjBlCGtqRNF+BjTXNHbY2wjkM4f5sWljjhQu8J8CAi47gqlAtCNevZU2o6AuC3OTbMR4=
12
+ gem: reccore
13
+ on:
14
+ tags: true
15
+ repo: IceProd/reccore
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,19 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'bundler'
4
+ gem 'rake'
5
+ gem 'nokogiri'
6
+
7
+ group :development do
8
+ gem 'pry'
9
+ gem 'awesome_print'
10
+ gem 'json'
11
+ end
12
+
13
+ group :test do
14
+ gem 'coveralls'
15
+ gem 'rspec'
16
+ end
17
+
18
+ # Specify your gem's dependencies in revepast.gemspec
19
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Mekaret Eriker
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ [![Stories in Ready](https://badge.waffle.io/IceProd/reccore.png?label=ready&title=Ready)](https://waffle.io/IceProd/reccore)
2
+ [![Dependency Status](https://gemnasium.com/IceProd/reccore.svg)](https://gemnasium.com/IceProd/reccore)
3
+ [![Build Status](https://travis-ci.org/IceProd/reccore.svg?branch=master)](https://travis-ci.org/IceProd/reccore)
4
+ [![security](https://hakiri.io/github/IceProd/reccore/master.svg)](https://hakiri.io/github/IceProd/reccore/master)
5
+
6
+ # Reccore
7
+
8
+ A ruby library for [Eve Central](https://eve-central.com/home/develop.html)
9
+
10
+ This is currently a **work in progress**.
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ ```ruby
17
+ gem 'reccore'
18
+ ```
19
+
20
+ And then execute:
21
+
22
+ $ bundle
23
+
24
+ Or install it yourself as:
25
+
26
+ $ gem install reccore
27
+
28
+ ## Tests
29
+
30
+
31
+ ```ruby
32
+ RSpec.describe Reccore do
33
+ it 'Perform a request to Eve Central and return values' do
34
+ tritanium = Reccore::EC.new
35
+ puts "The min sell value for tritanium is #{tritanium.get_sell_min('34')}"
36
+ end
37
+ end
38
+ ```
39
+
40
+ Result
41
+ ```ruby
42
+ The min sell value for tritanium is 5.25
43
+
44
+ ```
45
+
46
+ ## License
47
+
48
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
49
+
50
+
51
+ ## CCP Copyright Notice
52
+
53
+ EVE Online and the EVE logo are the registered trademarks of CCP hf. All rights are reserved worldwide. All other trademarks are the property of their respective owners. EVE Online, the EVE logo, EVE and all associated logos and designs are the intellectual property of CCP hf. All artwork, screenshots, characters, vehicles, storylines, world facts or other recognizable features of the intellectual property relating to these trademarks are likewise the intellectual property of CCP hf. CCP hf. has granted permission to evepaste to use EVE Online and all associated logos and designs for promotional and information purposes on its website but does not endorse, and is not in any way affiliated with, evepaste. CCP is in no way responsible for the content on or functioning of this website, nor can it be liable for any damage arising from the use of this website.
54
+
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task :default => :spec
7
+ task :test => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'reccore'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/lib/reccore.rb ADDED
@@ -0,0 +1,147 @@
1
+ require 'nokogiri'
2
+ require 'open-uri'
3
+
4
+ require 'reccore/version'
5
+ require 'reccore/vash'
6
+ require 'reccore/marketstat'
7
+
8
+ module Reccore
9
+ class << self; attr_accessor :cache end
10
+ @cache = Vash.new
11
+
12
+ # :volume => element.css('buy/volume').text,
13
+ # :avg => element.css('buy/avg').text,
14
+ # :max => element.css('buy/max').text,
15
+ # :min => element.css('buy/min').text,
16
+ # :stddev => element.css('buy/stddev').text,
17
+ # :median => element.css('buy/median').text,
18
+ # :percentile => element.css('buy/percentile').text
19
+
20
+ class EC
21
+ def get_buy_volume(typeid)
22
+ if Reccore.cache[typeid.to_s].nil?
23
+ Reccore::Marketstat.new(:typeid => typeid.to_s)
24
+ Reccore.cache[typeid.to_s].first[:buy][:volume]
25
+ else
26
+ Reccore.cache[typeid.to_s].first[:buy][:volume]
27
+ end
28
+ end
29
+
30
+ def get_buy_avg(typeid)
31
+ if Reccore.cache[typeid.to_s].nil?
32
+ Reccore::Marketstat.new(:typeid => typeid.to_s)
33
+ Reccore.cache[typeid.to_s].first[:buy][:avg]
34
+ else
35
+ Reccore.cache[typeid.to_s].first[:buy][:avg]
36
+ end
37
+ end
38
+
39
+ def get_buy_max(typeid)
40
+ if Reccore.cache[typeid.to_s].nil?
41
+ Reccore::Marketstat.new(:typeid => typeid.to_s)
42
+ Reccore.cache[typeid.to_s].first[:buy][:max]
43
+ else
44
+ Reccore.cache[typeid.to_s].first[:buy][:max]
45
+ end
46
+ end
47
+
48
+ def get_buy_min(typeid)
49
+ if Reccore.cache[typeid.to_s].nil?
50
+ Reccore::Marketstat.new(:typeid => typeid.to_s)
51
+ Reccore.cache[typeid.to_s].first[:buy][:min]
52
+ else
53
+ Reccore.cache[typeid.to_s].first[:buy][:min]
54
+ end
55
+ end
56
+
57
+ def get_buy_stddev(typeid)
58
+ if Reccore.cache[typeid.to_s].nil?
59
+ Reccore::Marketstat.new(:typeid => typeid.to_s)
60
+ Reccore.cache[typeid.to_s].first[:buy][:stddev]
61
+ else
62
+ Reccore.cache[typeid.to_s].first[:buy][:stddev]
63
+ end
64
+ end
65
+
66
+ def get_buy_median(typeid)
67
+ if Reccore.cache[typeid.to_s].nil?
68
+ Reccore::Marketstat.new(:typeid => typeid.to_s)
69
+ Reccore.cache[typeid.to_s].first[:buy][:median]
70
+ else
71
+ Reccore.cache[typeid.to_s].first[:buy][:median]
72
+ end
73
+ end
74
+
75
+ def get_buy_percentile(typeid)
76
+ if Reccore.cache[typeid.to_s].nil?
77
+ Reccore::Marketstat.new(:typeid => typeid.to_s)
78
+ Reccore.cache[typeid.to_s].first[:buy][:percentile]
79
+ else
80
+ Reccore.cache[typeid.to_s].first[:buy][:percentile]
81
+ end
82
+ end
83
+
84
+ def get_sell_volume(typeid)
85
+ if Reccore.cache[typeid.to_s].nil?
86
+ Reccore::Marketstat.new(:typeid => typeid.to_s)
87
+ Reccore.cache[typeid.to_s].last[:sell][:volume]
88
+ else
89
+ Reccore.cache[typeid.to_s].last[:sell][:volume]
90
+ end
91
+ end
92
+
93
+ def get_sell_avg(typeid)
94
+ if Reccore.cache[typeid.to_s].nil?
95
+ Reccore::Marketstat.new(:typeid => typeid.to_s)
96
+ Reccore.cache[typeid.to_s].last[:sell][:avg]
97
+ else
98
+ Reccore.cache[typeid.to_s].last[:sell][:avg]
99
+ end
100
+ end
101
+
102
+ def get_sell_max(typeid)
103
+ if Reccore.cache[typeid.to_s].nil?
104
+ Reccore::Marketstat.new(:typeid => typeid.to_s)
105
+ Reccore.cache[typeid.to_s].last[:sell][:max]
106
+ else
107
+ Reccore.cache[typeid.to_s].last[:sell][:max]
108
+ end
109
+ end
110
+
111
+ def get_sell_min(typeid)
112
+ if Reccore.cache[typeid.to_s].nil?
113
+ Reccore::Marketstat.new(:typeid => typeid.to_s)
114
+ Reccore.cache[typeid.to_s].last[:sell][:min]
115
+ else
116
+ Reccore.cache[typeid.to_s].last[:sell][:min]
117
+ end
118
+ end
119
+
120
+ def get_sell_stddev(typeid)
121
+ if Reccore.cache[typeid.to_s].nil?
122
+ Reccore::Marketstat.new(:typeid => typeid.to_s)
123
+ Reccore.cache[typeid.to_s].last[:sell][:stddev]
124
+ else
125
+ Reccore.cache[typeid.to_s].last[:sell][:stddev]
126
+ end
127
+ end
128
+
129
+ def get_sell_median(typeid)
130
+ if Reccore.cache[typeid.to_s].nil?
131
+ Reccore::Marketstat.new(:typeid => typeid.to_s)
132
+ Reccore.cache[typeid.to_s].last[:sell][:median]
133
+ else
134
+ Reccore.cache[typeid.to_s].last[:sell][:median]
135
+ end
136
+ end
137
+
138
+ def get_sell_percentile(typeid)
139
+ if Reccore.cache[typeid.to_s].nil?
140
+ Reccore::Marketstat.new(:typeid => typeid.to_s)
141
+ Reccore.cache[typeid.to_s].last[:sell][:percentile]
142
+ else
143
+ Reccore.cache[typeid.to_s].last[:sell][:percentile]
144
+ end
145
+ end
146
+ end
147
+ end
@@ -0,0 +1,78 @@
1
+ module Reccore
2
+ # Endpoint: http://api.eve-central.com/api/marketstat
3
+ # Purpose: Retrieve aggregate statistics for the items specified.
4
+ # Allowed methods: GET (parameter list), POST (form data)
5
+ # Return data: XML
6
+ class Marketstat
7
+ class << self; attr_reader :endpoint end
8
+ @endpoint = 'http://api.eve-central.com/api/marketstat?'
9
+
10
+ # hours : Statistics from the last X specified hours. Defaults to 24.
11
+ # typeid : The type ID of the item you are requesting. I.e., 34 for Tritanium. Can be specified more than once.
12
+ # minQ : The minimum quantity in an order to consider it for the statistics.
13
+ # regionlimit : Restrict statistics to a region. Can be specified more than once.
14
+ # usesystem : Restrict statistics to a system.
15
+ def initialize(options = {})
16
+ # hours = 24, typeid, minQ = nil, regionlimit = nil, usesystem = '30000142' (Jita)
17
+ @args = ''
18
+ @args += "hours=#{options[:hours]}&" unless options[:hours].nil?
19
+ parse_typeid(options[:typeid])
20
+ @args += "minQ=#{options[:minQ]}&" unless options[:minQ].nil?
21
+ parse_regionlimit(options[:regionlimit]) unless options[:regionlimit].nil?
22
+ @args += 'usesystem=30000142&' if options[:regionlimit].nil?
23
+ @args += "usesystem=#{options[:usesystem]}&" unless options[:usesystem].nil?
24
+ xml = Nokogiri::XML(open(Marketstat.endpoint + @args.chomp('&')))
25
+ update(xml)
26
+ Reccore.cache.cleanup!
27
+ end
28
+
29
+ def parse_typeid(typeid)
30
+ if typeid.is_a?(Array)
31
+ typeid.each { |type| @args += "typeid=#{type}&" }
32
+ else
33
+ @args += "typeid=#{typeid}&"
34
+ end
35
+ end
36
+
37
+ def parse_regionlimit(regionlimit)
38
+ if regionlimit.is_a?(Array)
39
+ regionlimit.each { |region| @args += "regionlimit=#{region}&" }
40
+ else
41
+ @args += "regionlimit=#{regionlimit}&"
42
+ end
43
+ end
44
+
45
+ def update(xml)
46
+ elements = xml.xpath('//type')
47
+ elements.each do |element|
48
+ Reccore.cache[element['id'], 3600] = update_buy(element), update_sell(element)
49
+ end
50
+ end
51
+
52
+ def update_buy(element)
53
+ {:buy =>
54
+ {:volume => element.css('buy/volume').text,
55
+ :avg => element.css('buy/avg').text,
56
+ :max => element.css('buy/max').text,
57
+ :min => element.css('buy/min').text,
58
+ :stddev => element.css('buy/stddev').text,
59
+ :median => element.css('buy/median').text,
60
+ :percentile => element.css('buy/percentile').text,
61
+ },
62
+ }
63
+ end
64
+
65
+ def update_sell(element)
66
+ {:sell =>
67
+ {:volume => element.css('sell/volume').text,
68
+ :avg => element.css('sell/avg').text,
69
+ :max => element.css('sell/max').text,
70
+ :min => element.css('sell/min').text,
71
+ :stddev => element.css('sell/stddev').text,
72
+ :median => element.css('sell/median').text,
73
+ :percentile => element.css('sell/percentile').text,
74
+ },
75
+ }
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,11 @@
1
+ module Reccore
2
+ # Endpoint: http://api.eve-central.com/api/quicklook
3
+ # Purpose: Retrieve all of the available market orders, including prices, stations, order IDs, volumes, etc.
4
+ # Allowed methods: GET (parameter list), POST (form data)
5
+ # Return type: XML
6
+ # ref: http://dev.eve-central.com/evec-api/start
7
+ class Quicklook
8
+ class << self; attr_reader :endpoint end
9
+ @endpoint = 'http://api.eve-central.com/api/quicklook'
10
+ end
11
+ end
@@ -0,0 +1,113 @@
1
+ #############################################################################
2
+ # Class: Vash (Ruby Volatile Hash)
3
+ # Hash that returns values only for a short time. This is useful as a cache
4
+ # where I/O is involved. The primary goal of this object is to reduce I/O
5
+ # access and due to the nature of I/O being slower then memory, you should also
6
+ # see a gain in quicker response times.
7
+ #
8
+ # For example, if Person.first found the first person from the database & cache
9
+ # was an instance of Vash then the following would only contact the database for
10
+ # the first iteration:
11
+ #
12
+ # > cache = Vash.new
13
+ # > 1000.times {cache[:person] ||= Person.first}
14
+ #
15
+ # However if you did the following immediately following that command it would
16
+ # hit the database again:
17
+ #
18
+ # > sleep 61
19
+ # > cache[:person] ||= Person.first
20
+ #
21
+ # The reason is that there is a default Time-To-Live of 60 seconds. You can
22
+ # also set a custom TTL of 10 seconds like so:
23
+ #
24
+ # > cache[:person, 10] = Person.first
25
+ #
26
+ # The Vash object will forget any answer that is requested after the specified
27
+ # TTL. It is a good idea to manually clean things up from time to time because
28
+ # it is possible that you'll cache data but never again access it and therefor
29
+ # it will stay in memory after the TTL has expired. To clean up the Vash object,
30
+ # call the method: cleanup!
31
+ #
32
+ # > sleep 11 # At this point the prior person ttl will be expired
33
+ # # but the person key and value will still exist.
34
+ # > cache # This will still show the the entire set of keys
35
+ # # regardless of the TTL, the :person will still exist
36
+ # > cache.cleanup! # All of the TTL's will be inspected and the expired
37
+ # # :person key will be deleted.
38
+ #
39
+ # The cleanup must be manually called because the purpose of the Vash is to
40
+ # lessen needless I/O calls and gain speed not to slow it down with regular
41
+ # maintenance.
42
+ class Vash < Hash
43
+ def initialize(constructor = {})
44
+ @register ||= {} # remembers expiration time of every key
45
+ if constructor.is_a?(Hash)
46
+ super()
47
+ merge(constructor)
48
+ else
49
+ super(constructor)
50
+ end
51
+ end
52
+
53
+ alias_method :regular_writer, :[]= unless method_defined?(:regular_writer)
54
+ alias_method :regular_reader, :[] unless method_defined?(:regular_reader)
55
+
56
+ def [](key)
57
+ sterilize(key)
58
+ clear(key) if expired?(key)
59
+ regular_reader(key)
60
+ end
61
+
62
+ def []=(key, *args)
63
+ # a little bit o variable hacking to support (h[key, ttl] = value), which will come
64
+ # accross as (key, [ttl, value]) whereas (h[key]=value) comes accross as (key, [value])
65
+ if args.length == 2
66
+ value = args[1]
67
+ ttl = args[0]
68
+ elsif args.length == 1
69
+ value = args[0]
70
+ ttl = 60
71
+ else
72
+ fail ArgumentError, "Wrong number of arguments, expected 2 or 3, received: #{args.length + 1}\n"\
73
+ 'Example Usage: volatile_hash[:key]=value OR volatile_hash[:key, ttl]=value'
74
+ end
75
+ sterilize(key)
76
+ ttl(key, ttl)
77
+ regular_writer(key, value)
78
+ end
79
+
80
+ def merge(hsh)
81
+ hsh.map { |key, _value| self[sterile(key)] = hsh[key] }
82
+ self
83
+ end
84
+
85
+ def cleanup!
86
+ now = Time.now.to_i
87
+ @register.map { |k, v| clear(k) if v < now }
88
+ end
89
+
90
+ def clear(key)
91
+ sterilize(key)
92
+ @register.delete key
93
+ delete key
94
+ end
95
+
96
+ private
97
+
98
+ def expired?(key)
99
+ Time.now.to_i > @register[key].to_i
100
+ end
101
+
102
+ def ttl(key, secs = 60)
103
+ @register[key] = Time.now.to_i + secs.to_i
104
+ end
105
+
106
+ def sterile(key)
107
+ String === key ? key.chomp('!').chomp('=') : key.to_s.chomp('!').chomp('=').to_sym
108
+ end
109
+
110
+ def sterilize(key)
111
+ key = sterile(key)
112
+ end
113
+ end
@@ -0,0 +1,3 @@
1
+ module Reccore
2
+ VERSION = '0.1.3'
3
+ end
data/reccore.gemspec ADDED
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'reccore/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'reccore'
8
+ spec.version = Reccore::VERSION
9
+ spec.authors = ['Mekaret Eriker']
10
+ spec.email = ['mekaret@revhosts.net']
11
+
12
+ spec.summary = 'A Ruby librairy for Eve Central.'
13
+ spec.description = 'A Ruby librairy for Eve Central.'
14
+ spec.homepage = 'https://github.com/IceProd/revepast'
15
+ spec.license = 'MIT'
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ else
22
+ fail 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
27
+ spec.bindir = 'exe'
28
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ['lib']
30
+
31
+ spec.add_development_dependency 'bundler', '~> 1.10'
32
+ spec.add_development_dependency 'rake', '~> 10.0'
33
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: reccore
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - Mekaret Eriker
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-08-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: A Ruby librairy for Eve Central.
42
+ email:
43
+ - mekaret@revhosts.net
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - .rubocop.yml
50
+ - .travis.yml
51
+ - CODE_OF_CONDUCT.md
52
+ - Gemfile
53
+ - LICENSE.txt
54
+ - README.md
55
+ - Rakefile
56
+ - bin/console
57
+ - bin/setup
58
+ - lib/reccore.rb
59
+ - lib/reccore/marketstat.rb
60
+ - lib/reccore/quicklook.rb
61
+ - lib/reccore/vash.rb
62
+ - lib/reccore/version.rb
63
+ - reccore.gemspec
64
+ homepage: https://github.com/IceProd/revepast
65
+ licenses:
66
+ - MIT
67
+ metadata:
68
+ allowed_push_host: ! 'TODO: Set to ''http://mygemserver.com'''
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 2.4.5
86
+ signing_key:
87
+ specification_version: 4
88
+ summary: A Ruby librairy for Eve Central.
89
+ test_files: []