revepast 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/Gemfile +1 -0
- data/README.md +2 -0
- data/lib/revepast/exceptions.rb +9 -0
- data/lib/revepast/parser/cargo_scan.rb +12 -5
- data/lib/revepast/parser/eft.rb +18 -9
- data/lib/revepast/parser.rb +11 -4
- data/lib/revepast/version.rb +1 -1
- data/lib/revepast.rb +19 -22
- data/revepast.gemspec +1 -1
- metadata +4 -4
- data/lib/revepast/parser/test.rb +0 -21
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YTBiM2I4NjdiNjIzZThjOGQ1ODc1Njc0MDJkZDRlYTcwZjA3YWI4Zg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OTA3N2FhMmNkOGVlZGI4MDQzZDYyNmRmZThmOGM2YmMxMDJiMTZkNw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MWQ0OWMwMGZlYjk0OTdjYjVkMWMzNGQ4NGVkZmEyNTgyYTAzNDc0Y2RjN2Vh
|
10
|
+
MDA3ZDAwYjM0ZGZkYjBmZGNjN2U5MGM2ZmQyYTNjZmQ5MTJlOTQxMzI5ZWVm
|
11
|
+
NDc2MTA5OTE0NDI3MzMxNGYzZDVlNTJhZDQyZWRhMTUzMzFkMWY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NTQzOTIyNzA5ZmQ0ZDUzMWIyNzc3ZjYwNTYwMGJmOTJiYzIzZDVmNGRiOWVj
|
14
|
+
YWIzMzBiNzc1NjdmMGIzNWFiN2ExYmY2NmRjMTkzOTA4OTA2NGEzNzk0YWU1
|
15
|
+
ZTIxYWJlYTEzZWY3YTljNzhiOWNlYTgyODk2MWYzM2QyYzhiYzI=
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/revepast.png)](http://badge.fury.io/rb/revepast)
|
1
2
|
[![Coverage Status](https://coveralls.io/repos/Mekaret/revepast/badge.svg?branch=master&service=github)](https://coveralls.io/github/Mekaret/revepast?branch=master)
|
2
3
|
[![Build Status](https://travis-ci.org/Mekaret/revepast.svg?branch=master)](https://travis-ci.org/Mekaret/revepast)
|
3
4
|
|
4
5
|
# Revepast
|
5
6
|
|
6
7
|
A ruby library to help parse various things that are copy/pastable from the Eve Online UI.
|
8
|
+
Largely inspired from [Evepaste](https://github.com/evepraisal/evepaste).
|
7
9
|
|
8
10
|
This is currently a **work in progress**.
|
9
11
|
|
@@ -1,14 +1,21 @@
|
|
1
1
|
module Revepast
|
2
2
|
module Parser
|
3
3
|
class CargoScan
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
autoload :Utils, 'revepast/parser'
|
5
|
+
include Revepast::Parser
|
6
|
+
|
7
|
+
attr_reader :result, :bad_lines
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@Utils = Utils.new
|
11
|
+
@result = {}
|
12
|
+
@bad_lines = []
|
13
|
+
result = parse
|
8
14
|
end
|
9
15
|
|
10
16
|
def parse
|
11
|
-
|
17
|
+
lines = @Utils.sanitize(Revepast.str)
|
18
|
+
@result, @bad_lines = @Utils.parse_listing(lines)
|
12
19
|
end
|
13
20
|
end
|
14
21
|
end
|
data/lib/revepast/parser/eft.rb
CHANGED
@@ -6,14 +6,14 @@ module Revepast
|
|
6
6
|
|
7
7
|
attr_reader :result, :bad_lines
|
8
8
|
|
9
|
-
def initialize
|
9
|
+
def initialize
|
10
10
|
@Utils = Utils.new
|
11
11
|
@result = {}
|
12
12
|
@bad_lines = []
|
13
|
-
result = parse
|
13
|
+
result = parse
|
14
14
|
end
|
15
15
|
|
16
|
-
def parse
|
16
|
+
def parse
|
17
17
|
ammo_pattern = /^([\S ]+), ?([\S ]+)$/
|
18
18
|
blacklist = ['[empty high slot]',
|
19
19
|
'[empty low slot]',
|
@@ -21,13 +21,22 @@ module Revepast
|
|
21
21
|
'[empty rig slot]',
|
22
22
|
'[empty subsystem slot]']
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
sanitize = @Utils.sanitize(Revepast.str)
|
25
|
+
lines = []
|
26
|
+
sanitize.each do |line|
|
27
|
+
unless blacklist.include? line.downcase
|
28
|
+
lines << line
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
begin
|
33
|
+
lines.first =~ /^(\[).*(\])$/
|
34
|
+
ship = lines.first.match(ammo_pattern)[1].tr('[]', '')
|
35
|
+
fit_name = lines.first.match(ammo_pattern)[2].tr('[]', '')
|
36
|
+
rescue
|
37
|
+
raise Unparsable.new("Invalid EFT title line")
|
29
38
|
end
|
30
|
-
matches, bad_lines = @Utils.regex_match_lines(ammo_pattern,
|
39
|
+
matches, bad_lines = @Utils.regex_match_lines(ammo_pattern, lines[1..-1])
|
31
40
|
matches2, bad_lines2 = @Utils.parse_listing(bad_lines)
|
32
41
|
|
33
42
|
@bad_lines = bad_lines2
|
data/lib/revepast/parser.rb
CHANGED
@@ -1,8 +1,17 @@
|
|
1
1
|
module Revepast
|
2
2
|
module Parser
|
3
|
+
require "revepast/parser/eft"
|
4
|
+
require "revepast/parser/cargo_scan"
|
3
5
|
class Utils
|
4
6
|
def sanitize(str)
|
5
|
-
|
7
|
+
result = []
|
8
|
+
str.each_line do |line|
|
9
|
+
line = line.chomp.gsub /^$\n/, ''
|
10
|
+
unless line.nil? || line == ""
|
11
|
+
result << line
|
12
|
+
end
|
13
|
+
end
|
14
|
+
return result
|
6
15
|
end
|
7
16
|
|
8
17
|
def regex_match_lines(regex, lines)
|
@@ -10,10 +19,8 @@ module Revepast
|
|
10
19
|
bad_lines = Array.new
|
11
20
|
lines.each do |line|
|
12
21
|
if line.match(regex)
|
13
|
-
# p "--#{line.chomp}"
|
14
22
|
a = line.match(regex)
|
15
23
|
matches.push(a.captures)
|
16
|
-
# p matches
|
17
24
|
else
|
18
25
|
bad_lines.push(line.chomp)
|
19
26
|
end
|
@@ -34,7 +41,7 @@ module Revepast
|
|
34
41
|
matches3, bad_lines3 = regex_match_lines(listing_re3, bad_lines2)
|
35
42
|
|
36
43
|
items = Hash.new { |h, k| h[k] = 0 }
|
37
|
-
matches.each do |
|
44
|
+
matches.each do |count, name|
|
38
45
|
items[name.strip] += count.to_i
|
39
46
|
end
|
40
47
|
matches2.each do |name, count|
|
data/lib/revepast/version.rb
CHANGED
data/lib/revepast.rb
CHANGED
@@ -1,32 +1,29 @@
|
|
1
1
|
require "revepast/version"
|
2
|
+
require "revepast/exceptions"
|
3
|
+
require "revepast/parser"
|
2
4
|
|
3
5
|
module Revepast
|
4
|
-
class
|
5
|
-
end
|
6
|
-
|
7
|
-
module Parser
|
8
|
-
autoload :Parser, 'revepast/parser'
|
9
|
-
end
|
10
|
-
|
11
|
-
class Sort
|
12
|
-
autoload :EFT, 'revepast/parser/eft'
|
13
|
-
include Revepast::Parser
|
14
|
-
|
15
|
-
attr_reader :result, :bad_lines
|
16
|
-
|
17
|
-
def initialize(str)
|
18
|
-
eft_parse = EFT.new(str)
|
19
|
-
@result = eft_parse.result
|
20
|
-
@bad_lines = eft_parse.bad_lines
|
21
|
-
end
|
22
|
-
end
|
6
|
+
class << self; attr_accessor :str; end
|
23
7
|
|
24
8
|
class Parse
|
25
9
|
attr_reader :result
|
26
10
|
def initialize (str)
|
27
|
-
|
28
|
-
|
29
|
-
|
11
|
+
Revepast.str = str
|
12
|
+
parser_table = [ "EFT", "CargoScan" ]
|
13
|
+
parser_table.each do |classname|
|
14
|
+
begin
|
15
|
+
parse = Object.const_get("Revepast::Parser").const_get(classname).new
|
16
|
+
if parse then
|
17
|
+
result = parse.result
|
18
|
+
bad_lines = parse.bad_lines
|
19
|
+
@result = [classname, result, bad_lines]
|
20
|
+
return
|
21
|
+
end
|
22
|
+
rescue Unparsable
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
raise Unparsable.new("No valid parser found for the givin text.")
|
30
27
|
end
|
31
28
|
end
|
32
29
|
|
data/revepast.gemspec
CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
|
|
11
11
|
|
12
12
|
spec.summary = "A Ruby library to help parse various things that are copy/pastable from the Eve Online"
|
13
13
|
spec.description = "Ruby library to help parse various things that are copy/pastable from the Eve Online"
|
14
|
-
spec.homepage = ""
|
14
|
+
spec.homepage = "https://github.com/Mekaret/revepast"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
17
17
|
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: revepast
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mekaret Eriker
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-12 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Ruby library to help parse various things that are copy/pastable from
|
14
14
|
the Eve Online
|
@@ -25,13 +25,13 @@ files:
|
|
25
25
|
- README.md
|
26
26
|
- Rakefile
|
27
27
|
- lib/revepast.rb
|
28
|
+
- lib/revepast/exceptions.rb
|
28
29
|
- lib/revepast/parser.rb
|
29
30
|
- lib/revepast/parser/cargo_scan.rb
|
30
31
|
- lib/revepast/parser/eft.rb
|
31
|
-
- lib/revepast/parser/test.rb
|
32
32
|
- lib/revepast/version.rb
|
33
33
|
- revepast.gemspec
|
34
|
-
homepage:
|
34
|
+
homepage: https://github.com/Mekaret/revepast
|
35
35
|
licenses:
|
36
36
|
- MIT
|
37
37
|
metadata:
|
data/lib/revepast/parser/test.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
# /usr/bin/ruby
|
2
|
-
|
3
|
-
input = {
|
4
|
-
"425mm AutoCannon II, Republic Fleet EMP M" => 3
|
5
|
-
}
|
6
|
-
|
7
|
-
expected_output = [
|
8
|
-
{
|
9
|
-
name: "425mm AutoCannon II",
|
10
|
-
ammo: "Republic Fleet EMP M",
|
11
|
-
quantity: 3
|
12
|
-
}
|
13
|
-
]
|
14
|
-
|
15
|
-
output = input.inject([]) do |memo, (key, quantity)|
|
16
|
-
name, ammo = key.split(",")
|
17
|
-
memo << { name: name.strip, ammo: ammo.strip, quantity: quantity }
|
18
|
-
p memo
|
19
|
-
end
|
20
|
-
|
21
|
-
raise "don't match" if output != expected_output
|