hasami 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2834a1d6e6ef55a2ec230cc7603f1960161f671f
4
+ data.tar.gz: 44d032af917c146262244dfc870ec3b2f4cb6467
5
+ SHA512:
6
+ metadata.gz: eda58bba8a8c310be3fbff88e458c3dfb37e65c62f3d59db57ca25b2951e11d6f237719810d446a3771e4b98848f8534dab3306c4f1f07635501d60ccfd09171
7
+ data.tar.gz: d880be4cae3a894089f5ec55be8d9c423ba6965d2248e4d55ddbd903456bb754acc05131a9102ddd16a5c0f4615e8f00bacb6c1b79d0df408d3f43bdd85fdd2f
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.11.0
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at quietmes@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in hasami.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 陳均均 (jiunjiun)
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 all
13
+ 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 THE
21
+ SOFTWARE.
22
+
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 jiunjiun
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,112 @@
1
+ # Hasami
2
+
3
+ [![Build Status](https://travis-ci.org/jiunjiun/hasami.svg?branch=master)](https://travis-ci.org/jiunjiun/hasami)
4
+ [![Code Climate](https://codeclimate.com/repos/566d52fd97d7241309001da7/badges/37f78d35576130bc85fc/gpa.svg)](https://codeclimate.com/repos/566d52fd97d7241309001da7/feed)
5
+ [![security](https://hakiri.io/github/jiunjiun/hasami/master.svg)](https://hakiri.io/github/jiunjiun/hasami/master)
6
+
7
+ 桃園國際機場航班資訊 API
8
+
9
+ This API helper get Taoyuan International Airport flight info
10
+
11
+ source: [http://www.taoyuan-airport.com/chinese/flighttxt](http://www.taoyuan-airport.com/chinese/flighttxt)
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ ```ruby
18
+ gem 'hasami'
19
+ ```
20
+
21
+ And then execute:
22
+
23
+ $ bundle
24
+
25
+ Or install it yourself as:
26
+
27
+ $ gem install hasami
28
+
29
+ #Usage
30
+
31
+ ```ruby
32
+ require 'hasami'
33
+ ```
34
+
35
+ ### All flights
36
+ ```
37
+ haha = Hasami.new
38
+ haha.flights # All flights
39
+ ```
40
+
41
+ ###Flight attribute
42
+
43
+ ```
44
+ p haha.flights.first
45
+ ```
46
+
47
+ ```
48
+ @raw=["2", "A", "CI", "中華航空", "109", "B9", "2015/07/24", "00:05:00", "2015/07/24", "00:15:00", "NRT", "Tokyo", "東京", "已到ARRIVED", "B737-800", "", "", "", "", ""],
49
+ @terminal="T2",
50
+ @kind="Arrivals",
51
+ @code="CI",
52
+ @code_zh="中華航空",
53
+ @flight="109",
54
+ @gate="B9",
55
+ @datetime=#<DateTime: 2015-07-24T00:05:00+00:00 ((2457228j,300s,0n),+0s,2299161j)>,
56
+ @expected_datetime=#<DateTime: 2015-07-24T00:15:00+00:00 ((2457228j,900s,0n),+0s,2299161j)>,
57
+ @destination=#<Destination:0x007febbb3e40a0
58
+ @iata="NRT",
59
+ @en="Tokyo",
60
+ @zh="東京">,
61
+ @flight_status="已到ARRIVED",
62
+ @aircraft_type="B737-800",
63
+ @other_route=#<Destination:0x007febba876cb8
64
+ @iata="",
65
+ @en="",
66
+ @zh="">,
67
+ @baggage_carousel="",
68
+ @check_in_counter=""
69
+ ```
70
+
71
+ or
72
+
73
+ ```
74
+ p haha.flights.first.terminal # "T2"
75
+ ```
76
+
77
+ ### Arrivals
78
+ ```
79
+ p haha.arrivals
80
+ ```
81
+
82
+ ### Departure
83
+ ```
84
+ p haha.departure
85
+ ```
86
+
87
+ ### Yesterday, Today, Tomorrow
88
+ ```
89
+ p haha.yesterday
90
+ p haha.today
91
+ p haha.tomorrow
92
+ ```
93
+
94
+ ### Departure by today
95
+ ```
96
+ p haha.departure.today
97
+ ```
98
+
99
+ ## Development
100
+
101
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
102
+
103
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
104
+
105
+ ## Contributing
106
+
107
+ Bug reports and pull requests are welcome on GitHub at https://github.com/jiunjiun/hasami. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
108
+
109
+
110
+ ## Copyright / License
111
+ * Copyright (c) 2015 jiunjiun (quietmes At gmail.com)
112
+ * The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "hasami"
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,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/hasami.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'hasami/settings'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "hasami"
8
+ spec.version = HasamiSettings::VERSION
9
+ spec.authors = ["jiunjiun"]
10
+ spec.email = ["quietmes@gmail.com"]
11
+
12
+ spec.summary = %q{Hasami}
13
+ spec.description = %q{This API helper get Taoyuan airport flight info}
14
+ spec.homepage = ""
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.11"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3.0"
25
+
26
+ spec.add_dependency('curb')
27
+ spec.add_dependency('iconv')
28
+ spec.add_dependency('virtus')
29
+ end
@@ -0,0 +1,85 @@
1
+ class DestinationHaha
2
+ include Virtus.model
3
+
4
+ attribute :iata, String
5
+ attribute :en, String
6
+ attribute :zh, String
7
+ end
8
+
9
+ class FlightHaha
10
+ include Virtus.model
11
+
12
+ attribute :terminal, String #1: T1, 2:T2
13
+ attribute :kind, String #A: Arrivals, D: Departure
14
+ attribute :code, String
15
+ attribute :code_zh, String
16
+ attribute :flight, String
17
+ attribute :gate, String
18
+
19
+ attribute :datetime, DateTime
20
+ attribute :expected_datetime, DateTime
21
+
22
+ attribute :destination, DestinationHaha
23
+ attribute :flight_status, String
24
+
25
+ attribute :aircraft_type, String
26
+ attribute :other_route, DestinationHaha
27
+ attribute :baggage_carousel, String
28
+ attribute :check_in_counter, String
29
+
30
+ attribute :raw, Array
31
+
32
+
33
+ def initialize(raw_data)
34
+ self.raw = raw_data
35
+
36
+ # terminal
37
+ self.terminal = "T#{raw_data[0]}"
38
+
39
+ # kind
40
+ case raw_data[1]
41
+ when "A"
42
+ self.kind = "Arrivals"
43
+ when "D"
44
+ self.kind = "Departure"
45
+ end
46
+
47
+ # code
48
+ self.code = raw_data[2]
49
+
50
+ # code
51
+ self.code_zh = raw_data[3]
52
+
53
+ # flight
54
+ self.flight = raw_data[4]
55
+
56
+ # gate
57
+ self.gate = raw_data[5]
58
+
59
+ # datetime
60
+ self.datetime = "#{raw_data[6]} #{raw_data[7]} +08:00"
61
+
62
+ # expected_datetime
63
+ self.expected_datetime = "#{raw_data[8]} #{raw_data[9]} +08:00"
64
+
65
+ # destination
66
+ self.destination = DestinationHaha.new(iata: raw_data[10], en: raw_data[11], zh: raw_data[12])
67
+
68
+ # flight_status
69
+ self.flight_status = raw_data[13]
70
+
71
+ # aircraft_type
72
+ self.aircraft_type = raw_data[14]
73
+
74
+ # other_route
75
+ self.other_route = DestinationHaha.new(iata: raw_data[15], en: raw_data[16], zh: raw_data[17])
76
+
77
+ # baggage_carousel
78
+ self.baggage_carousel = raw_data[18]
79
+
80
+ # check_in_counter
81
+ self.check_in_counter = raw_data[19]
82
+ end
83
+ end
84
+
85
+
@@ -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
@@ -0,0 +1,17 @@
1
+ module FlightParse
2
+ # attr_accessor :url, :flights
3
+
4
+ def source_url(url = nil)
5
+ @url = url.nil? || url.length == 0 ? HasamiSettings::FLIGHT_URL : url
6
+ end
7
+
8
+ def flights_parse
9
+ @flights = []
10
+
11
+ ic = Iconv.new('UTF-8', 'BIG5')
12
+ row_data = ic.iconv(Curl.get(@url).body_str)
13
+ row_data.each_line do |line|
14
+ @flights << FlightHaha.new(line.split(',').map {|al| al = al.strip})
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,4 @@
1
+ module HasamiSettings
2
+ VERSION = "0.1.0"
3
+ FLIGHT_URL = 'http://www.taoyuan-airport.com/uploads/flightx/a_flight_v4.txt'
4
+ end
data/lib/hasami.rb ADDED
@@ -0,0 +1,46 @@
1
+ require 'curb'
2
+ require 'iconv'
3
+ require 'virtus'
4
+
5
+ require "hasami/settings"
6
+ require "hasami/flight_helper"
7
+ require "hasami/flight"
8
+ require "hasami/flight_parse"
9
+
10
+ class Hasami
11
+ include HasamiSettings
12
+ include FlightParse
13
+
14
+ def initialize(option = {})
15
+ source_url(option[:source_url])
16
+ flights_parse
17
+ end
18
+
19
+ def flights
20
+ @flights
21
+ end
22
+
23
+ def arrivals
24
+ @flights.arrivals
25
+ end
26
+
27
+ def departure
28
+ @flights.departure
29
+ end
30
+
31
+ def yesterday
32
+ @flights.yesterday
33
+ end
34
+
35
+ def today
36
+ @flights.today
37
+ end
38
+
39
+ def tomorrow
40
+ @flights.tomorrow
41
+ end
42
+
43
+ def by_datetime(datetime = DateTime.now)
44
+ @flights.by_datetime(datetime)
45
+ end
46
+ end
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hasami
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - jiunjiun
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-12-13 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.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
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
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: curb
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: iconv
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: virtus
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: This API helper get Taoyuan airport flight info
98
+ email:
99
+ - quietmes@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - CODE_OF_CONDUCT.md
108
+ - Gemfile
109
+ - LICENSE
110
+ - LICENSE.txt
111
+ - README.md
112
+ - Rakefile
113
+ - bin/console
114
+ - bin/setup
115
+ - hasami.gemspec
116
+ - lib/hasami.rb
117
+ - lib/hasami/flight.rb
118
+ - lib/hasami/flight_helper.rb
119
+ - lib/hasami/flight_parse.rb
120
+ - lib/hasami/settings.rb
121
+ homepage: ''
122
+ licenses:
123
+ - MIT
124
+ metadata: {}
125
+ post_install_message:
126
+ rdoc_options: []
127
+ require_paths:
128
+ - lib
129
+ required_ruby_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ required_rubygems_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ requirements: []
140
+ rubyforge_project:
141
+ rubygems_version: 2.4.8
142
+ signing_key:
143
+ specification_version: 4
144
+ summary: Hasami
145
+ test_files: []