Alohaha 0.0.3 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5500a23f3a8ec2d0fb6bdbb9385e9b98f25ca1c3
4
- data.tar.gz: 71a754e4b188b18bf24d2acdc35cba8854ff4c4b
3
+ metadata.gz: eba3048a00ea1fb3b68c9eaff2ad729d6ea3a8a1
4
+ data.tar.gz: 348e19efc00271490b902b58a3aadef12a49a037
5
5
  SHA512:
6
- metadata.gz: 7bdec080320ad75fb2797f34dd87459e492e4c65f1195d9d7d95c293f540dbb1046ddc3399c49deeecdb8dde17e3763b6fd0c87fe8fbd0f5834519313636d750
7
- data.tar.gz: f3b98242f517da1d524e543cf1c94247e9036f466b9c82e8fa6ff1820aa7455170cef39ffdb55d4a9c2effaeeba9a27b2c560ef827dc67a935959059f8e5e203
6
+ metadata.gz: ffb910580f30d22895fbe52eecc81e9de7a090a5186c7726d53d70642f71b305d95e9309851bce5d41c2187de414e3bf9aea77e1f852aaf620d8e16f5a1163be
7
+ data.tar.gz: ac35d75fe1de9a3ea1dd86a74ed379a2c78f44a459b07170998c795d0ac0409d70ee97cc160cf29a374dc9b8f29e6855970db78a601c6c0952477d5a7eb19ce8
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  #Alohaha
2
2
 
3
- This API helper get Taoyuan airport flight info
3
+ This API helper get Taoyuan International Airport flight info
4
4
 
5
5
  #Installation
6
6
 
data/alohaha.gemspec CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency "bundler", "~> 1.7"
22
22
  spec.add_development_dependency "rake", "~> 10.0"
23
23
 
24
- spec.add_dependency('open-uri')
24
+ spec.add_dependency('curb')
25
25
  spec.add_dependency('iconv')
26
26
  spec.add_dependency('virtus')
27
27
  end
data/lib/alohaha.rb CHANGED
@@ -1,8 +1,9 @@
1
- require 'open-uri'
1
+ require 'curb'
2
2
  require 'iconv'
3
3
  require 'virtus'
4
4
 
5
5
  require "alohaha/settings"
6
+ require "alohaha/flight_helper"
6
7
  require "alohaha/flight"
7
8
  require "alohaha/flight_parse"
8
9
 
@@ -19,11 +20,26 @@ class Alohaha
19
20
  end
20
21
 
21
22
  def arrivals
22
- @flights.select {|flights| flights.kind == 'Arrivals' }
23
+ @flights.arrivals
23
24
  end
24
25
 
25
26
  def departure
26
- @flights.select {|flights| flights.kind == 'Departure' }
27
+ @flights.departure
28
+ end
29
+
30
+ def yesterday
31
+ @flights.yesterday
32
+ end
33
+
34
+ def today
35
+ @flights.today
27
36
  end
28
- end
29
37
 
38
+ def tomorrow
39
+ @flights.tomorrow
40
+ end
41
+
42
+ def by_datetime(datetime = DateTime.now)
43
+ @flights.by_datetime(datetime)
44
+ end
45
+ end
@@ -1,4 +1,4 @@
1
- class Destination
1
+ class DestinationHaha
2
2
  include Virtus.model
3
3
 
4
4
  attribute :iata, String
@@ -6,7 +6,7 @@ class Destination
6
6
  attribute :zh, String
7
7
  end
8
8
 
9
- class Flight
9
+ class FlightHaha
10
10
  include Virtus.model
11
11
 
12
12
  attribute :terminal, String #1: T1, 2:T2
@@ -19,11 +19,11 @@ class Flight
19
19
  attribute :datetime, DateTime
20
20
  attribute :expected_datetime, DateTime
21
21
 
22
- attribute :destination, Destination
22
+ attribute :destination, DestinationHaha
23
23
  attribute :flight_status, String
24
24
 
25
25
  attribute :aircraft_type, String
26
- attribute :other_route, Destination
26
+ attribute :other_route, DestinationHaha
27
27
  attribute :baggage_carousel, String
28
28
  attribute :check_in_counter, String
29
29
 
@@ -57,13 +57,13 @@ class Flight
57
57
  self.gate = raw_data[5]
58
58
 
59
59
  # datetime
60
- self.datetime = "#{raw_data[6]} #{raw_data[7]}"
60
+ self.datetime = "#{raw_data[6]} #{raw_data[7]} +08:00"
61
61
 
62
62
  # expected_datetime
63
- self.expected_datetime = "#{raw_data[8]} #{raw_data[9]}"
63
+ self.expected_datetime = "#{raw_data[8]} #{raw_data[9]} +08:00"
64
64
 
65
65
  # destination
66
- self.destination = Destination.new(iata: raw_data[10], en: raw_data[11], zh: raw_data[12])
66
+ self.destination = DestinationHaha.new(iata: raw_data[10], en: raw_data[11], zh: raw_data[12])
67
67
 
68
68
  # flight_status
69
69
  self.flight_status = raw_data[13]
@@ -72,7 +72,7 @@ class Flight
72
72
  self.aircraft_type = raw_data[14]
73
73
 
74
74
  # other_route
75
- self.other_route = Destination.new(iata: raw_data[15], en: raw_data[16], zh: raw_data[17])
75
+ self.other_route = DestinationHaha.new(iata: raw_data[15], en: raw_data[16], zh: raw_data[17])
76
76
 
77
77
  # baggage_carousel
78
78
  self.baggage_carousel = raw_data[18]
@@ -0,0 +1,32 @@
1
+ class Array
2
+ def arrivals
3
+ self.select {|flights| flights.kind == 'Arrivals' }
4
+ end
5
+
6
+ def departure
7
+ self.select {|flights| flights.kind == 'Departure' }
8
+ end
9
+
10
+ def yesterday
11
+ self.select {|flights| flights.datetime.to_time > Date.today.prev_day.to_time && flights.datetime.to_time < Date.today.to_time }
12
+ end
13
+
14
+ def today
15
+ self.select {|flights| flights.datetime.to_time > Date.today.to_time && flights.datetime.to_time < Date.today.next_day.to_time }
16
+ end
17
+
18
+ def tomorrow
19
+ self.select {|flights| flights.datetime.to_time > Date.today.next_day.to_time }
20
+ end
21
+
22
+ def by_datetime(datetime = DateTime.now)
23
+ self.select {|flights| flights.datetime > datetime }
24
+ end
25
+
26
+ def filter_kind
27
+ {
28
+ Arrivals: self.select {|flights| flights.kind == 'Arrivals'},
29
+ Departure: self.select {|flights| flights.kind == 'Departure'}
30
+ }
31
+ end
32
+ end
@@ -9,9 +9,9 @@ module FlightParse
9
9
  @flights = []
10
10
 
11
11
  ic = Iconv.new('UTF-8', 'BIG5')
12
- row_data = ic.iconv(open(@url).read)
12
+ row_data = ic.iconv(Curl.get(@url).body_str)
13
13
  row_data.each_line do |line|
14
- @flights << Flight.new(line.split(',').map {|al| al = al.strip})
14
+ @flights << FlightHaha.new(line.split(',').map {|al| al = al.strip})
15
15
  end
16
16
  end
17
17
  end
@@ -1,4 +1,4 @@
1
1
  module Settings
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.5"
3
3
  FLIGHT_URL = 'http://www.taoyuan-airport.com/uploads/flightx/a_flight_v4.txt'
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Alohaha
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - jiunjiun
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-25 00:00:00.000000000 Z
11
+ date: 2015-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: open-uri
42
+ name: curb
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
@@ -95,6 +95,7 @@ files:
95
95
  - alohaha.gemspec
96
96
  - lib/alohaha.rb
97
97
  - lib/alohaha/flight.rb
98
+ - lib/alohaha/flight_helper.rb
98
99
  - lib/alohaha/flight_parse.rb
99
100
  - lib/alohaha/settings.rb
100
101
  homepage: ''
@@ -117,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
118
  version: '0'
118
119
  requirements: []
119
120
  rubyforge_project:
120
- rubygems_version: 2.4.5
121
+ rubygems_version: 2.4.8
121
122
  signing_key:
122
123
  specification_version: 4
123
124
  summary: Alohaha