airhelp 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +0 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +37 -0
- data/README.md +1 -0
- data/airhelp.gemspec +23 -0
- data/bin/airhelp +7 -0
- data/lib/airhelp.rb +25 -0
- data/lib/airhelp/processor.rb +59 -0
- data/lib/airhelp/record.rb +44 -0
- data/lib/airhelp/version.rb +3 -0
- metadata +102 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b0a3325dccfbcd3845553349850a7633f77d81b9
|
4
|
+
data.tar.gz: fe7cd7c8bccd297230064d08f7bca9884409d70d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c3bbb1a3e182b5023afde48fc47a1962c81eb2b9276e89d3a61d59ca5a38edb9ed36e3f9a18f3f365da8c3f2832ec29da5cc9503b24c234cb122036ef5da0706
|
7
|
+
data.tar.gz: e191b12545d4715aef2e43150b0b64158d2c8d4ef5d61b9e8b7c16eb874fc83843ca7e4226ae8ebff88b3b2e4d098938c89069d841b7b364652e030ce84429bf
|
data/.gitignore
ADDED
File without changes
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
airhelp (0.0.1)
|
5
|
+
activemodel (>= 4.2.0)
|
6
|
+
bundler (>= 1.10.0, < 2.0)
|
7
|
+
thor (>= 0.19.0)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
activemodel (4.2.4)
|
13
|
+
activesupport (= 4.2.4)
|
14
|
+
builder (~> 3.1)
|
15
|
+
activesupport (4.2.4)
|
16
|
+
i18n (~> 0.7)
|
17
|
+
json (~> 1.7, >= 1.7.7)
|
18
|
+
minitest (~> 5.1)
|
19
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
20
|
+
tzinfo (~> 1.1)
|
21
|
+
builder (3.2.2)
|
22
|
+
i18n (0.7.0)
|
23
|
+
json (1.8.3)
|
24
|
+
minitest (5.8.2)
|
25
|
+
thor (0.19.1)
|
26
|
+
thread_safe (0.3.5)
|
27
|
+
tzinfo (1.2.2)
|
28
|
+
thread_safe (~> 0.1)
|
29
|
+
|
30
|
+
PLATFORMS
|
31
|
+
ruby
|
32
|
+
|
33
|
+
DEPENDENCIES
|
34
|
+
airhelp!
|
35
|
+
|
36
|
+
BUNDLED WITH
|
37
|
+
1.10.6
|
data/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Airhelp
|
data/airhelp.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.expand_path('../lib/airhelp/version', __FILE__)
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = 'airhelp'
|
5
|
+
s.version = Airhelp::VERSION
|
6
|
+
s.date = '2015-10-28'
|
7
|
+
s.summary = "Airhelp test gem"
|
8
|
+
s.description = "Testing gem creation for airhelp test"
|
9
|
+
s.executables = 'airhelp'
|
10
|
+
s.authors = ['Michał Pawelski']
|
11
|
+
s.email = 'kontakt@proapi.eu'
|
12
|
+
s.files = `git ls-files`.split("\n")
|
13
|
+
s.homepage = 'http://github.com/proapi/airhelp'
|
14
|
+
s.license = 'MIT'
|
15
|
+
s.require_path = "lib"
|
16
|
+
|
17
|
+
s.required_ruby_version = '>= 1.9.3'
|
18
|
+
s.required_rubygems_version = '>= 1.8.11'
|
19
|
+
|
20
|
+
s.add_dependency 'bundler', '>= 1.10.0', '< 2.0'
|
21
|
+
s.add_dependency 'activemodel', '~> 4.2'
|
22
|
+
s.add_dependency 'thor', '~> 0.19'
|
23
|
+
end
|
data/bin/airhelp
ADDED
data/lib/airhelp.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'airhelp/processor'
|
3
|
+
require 'airhelp/record'
|
4
|
+
|
5
|
+
module Airhelp
|
6
|
+
class Base < Thor
|
7
|
+
desc "convert input.csv output.csv", "converts input.csv file to output.csv containing results"
|
8
|
+
long_desc <<-LONGDESC
|
9
|
+
`ruby airhelp.rb convert input.csv output.csv` will process input file as a csv to output file, and optionaly if errors occurs there are saved by default to errors.csv file.
|
10
|
+
|
11
|
+
The --errors option specifies the output file for saving errors.
|
12
|
+
|
13
|
+
> $ airhelp.rb convert input.csv output.csv
|
14
|
+
|
15
|
+
> from: Michał Pawelski
|
16
|
+
LONGDESC
|
17
|
+
option :errors, default: 'errors.csv', banner: 'optional flag to specify output file for errors'
|
18
|
+
def convert(input, output)
|
19
|
+
puts "input file: #{input} - output file: #{output}"
|
20
|
+
puts 'Start of prcessing...'
|
21
|
+
Processor.new(input, output, options).start
|
22
|
+
puts 'Ending...'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'csv'
|
2
|
+
|
3
|
+
module Airhelp
|
4
|
+
class Processor
|
5
|
+
|
6
|
+
attr_accessor :input, :output, :records, :errors, :index, :options
|
7
|
+
|
8
|
+
def initialize(input, output, options)
|
9
|
+
@input = input
|
10
|
+
@output = output
|
11
|
+
@records = Array.new
|
12
|
+
@errors = Array.new
|
13
|
+
@index = 0
|
14
|
+
@options = options
|
15
|
+
end
|
16
|
+
|
17
|
+
def start
|
18
|
+
read
|
19
|
+
write
|
20
|
+
errors if @errors.any?
|
21
|
+
end
|
22
|
+
|
23
|
+
def read
|
24
|
+
CSV.parse(File.read(@input), headers: true) do |row|
|
25
|
+
@index += 1
|
26
|
+
@records << Record.new(id: row[0], carrier_code: row[1], flight_number: row[2], flight_date: row[3])
|
27
|
+
end
|
28
|
+
puts "Parsed #{index} rows"
|
29
|
+
end
|
30
|
+
|
31
|
+
def write
|
32
|
+
CSV.open(@output, 'w', write_headers: true,
|
33
|
+
headers: Record.headers) do |writer|
|
34
|
+
valid_index = 0
|
35
|
+
@records.each do |record|
|
36
|
+
record.process
|
37
|
+
if record.valid?
|
38
|
+
writer << record.to_a
|
39
|
+
valid_index += 1
|
40
|
+
else
|
41
|
+
@errors << record
|
42
|
+
end
|
43
|
+
end
|
44
|
+
puts "Records counter: #{valid_index}"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def errors
|
49
|
+
CSV.open(@options[:errors], 'w', write_headers: true,
|
50
|
+
headers: Record.headers('errors')) do |writer|
|
51
|
+
@errors.each do |record|
|
52
|
+
writer << record.to_a
|
53
|
+
end
|
54
|
+
puts "Errors counter: #{@errors.size}"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'active_model'
|
2
|
+
|
3
|
+
module Airhelp
|
4
|
+
class Record
|
5
|
+
include ActiveModel::Validations
|
6
|
+
|
7
|
+
attr_accessor :id, :carrier_code, :carrier_code_type, :flight_number, :flight_date
|
8
|
+
|
9
|
+
validates :id, presence: true
|
10
|
+
validates :carrier_code, presence: true
|
11
|
+
validates :carrier_code_type, presence: true
|
12
|
+
validates :flight_number, presence: true
|
13
|
+
validates :flight_date, presence: true
|
14
|
+
validates_format_of :flight_date, with: /\A[0-9]{4}-[0-9]{2}-[0-9]{2}\z/
|
15
|
+
|
16
|
+
def initialize(params)
|
17
|
+
params.each do |key, value|
|
18
|
+
instance_variable_set("@#{key}", value)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def process
|
23
|
+
if @carrier_code =~ /\A[a-zA-Z]{3}\z/
|
24
|
+
@carrier_code_type = 'ICAO'
|
25
|
+
elsif @carrier_code =~ /\A[a-zA-Z]{2}\*?\z/
|
26
|
+
@carrier_code_type = 'IATA'
|
27
|
+
else
|
28
|
+
@carrier_code_type = 'unknown'
|
29
|
+
errors.add(:carrier_code_type, 'format is unknown')
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_a
|
34
|
+
array = [id, carrier_code, carrier_code_type, flight_number, flight_date]
|
35
|
+
array.push(errors.full_messages.join(';')) if errors.any?
|
36
|
+
array
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.headers(params=nil)
|
40
|
+
%w(id carrier_code carrier_code_type flight_number flight_date #{params})
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: airhelp
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Michał Pawelski
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-10-28 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.0
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '2.0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.10.0
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '2.0'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: activemodel
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '4.2'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '4.2'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: thor
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0.19'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0.19'
|
61
|
+
description: Testing gem creation for airhelp test
|
62
|
+
email: kontakt@proapi.eu
|
63
|
+
executables:
|
64
|
+
- airhelp
|
65
|
+
extensions: []
|
66
|
+
extra_rdoc_files: []
|
67
|
+
files:
|
68
|
+
- ".gitignore"
|
69
|
+
- Gemfile
|
70
|
+
- Gemfile.lock
|
71
|
+
- README.md
|
72
|
+
- airhelp.gemspec
|
73
|
+
- bin/airhelp
|
74
|
+
- lib/airhelp.rb
|
75
|
+
- lib/airhelp/processor.rb
|
76
|
+
- lib/airhelp/record.rb
|
77
|
+
- lib/airhelp/version.rb
|
78
|
+
homepage: http://github.com/proapi/airhelp
|
79
|
+
licenses:
|
80
|
+
- MIT
|
81
|
+
metadata: {}
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 1.9.3
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: 1.8.11
|
96
|
+
requirements: []
|
97
|
+
rubyforge_project:
|
98
|
+
rubygems_version: 2.4.8
|
99
|
+
signing_key:
|
100
|
+
specification_version: 4
|
101
|
+
summary: Airhelp test gem
|
102
|
+
test_files: []
|