notams 0.0.1 → 0.1
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.
- data/README.md +89 -10
- data/lib/notams.rb +69 -12
- data/lib/notams/version.rb +1 -1
- data/notams.gemspec +1 -1
- data/spec/notams_spec.rb +35 -4
- metadata +6 -6
data/README.md
CHANGED
@@ -1,8 +1,12 @@
|
|
1
|
-
# Notams
|
1
|
+
# Notams
|
2
2
|
|
3
3
|
A ruby gem for retrieving the currently active NOTAMs for an airport or a region.
|
4
|
-
Supports multiple airports/regions in one request. Pulls data from
|
5
|
-
Depends on `nokogiri` for the heavy lifting.
|
4
|
+
Supports multiple airports/regions in one request. Pulls data from
|
5
|
+
[FAA](http://www.faa.gov/) website. Depends on `nokogiri` for the heavy lifting.
|
6
|
+
|
7
|
+
[](http://travis-ci.org/tarakanbg/notams)
|
8
|
+
[](https://codeclimate.com/github/tarakanbg/notams)
|
9
|
+
[](https://gemnasium.com/tarakanbg/notams)
|
6
10
|
|
7
11
|
## Installation
|
8
12
|
|
@@ -20,10 +24,14 @@ Or install it yourself as:
|
|
20
24
|
|
21
25
|
## Usage
|
22
26
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
+
### Easy mode
|
28
|
+
|
29
|
+
The `.notams` method can be applied to any string literal or variable,
|
30
|
+
representing a valid ICAO code of an airport or FIR, or a comma-separated list
|
31
|
+
of airports/regions. It will return an array, containing all the **currently
|
32
|
+
active** NOTAMs for your selection. You can loop through the array to display or
|
33
|
+
parse individual notams. I figured this would be the most common use case. For
|
34
|
+
advanced usage and possible customizations [see below](#advanced-usage).
|
27
35
|
|
28
36
|
```ruby
|
29
37
|
icao = "lowi"
|
@@ -32,13 +40,84 @@ icao.notams # => returns an array containing all NOTAMs for Innsbruck airport
|
|
32
40
|
"lowi".notams # => same as above
|
33
41
|
|
34
42
|
icao = "lqsa,lqsb"
|
35
|
-
icao.notams # => returns an array containing all NOTAMs for Sarajevo Airport
|
43
|
+
icao.notams # => returns an array containing all NOTAMs for Sarajevo Airport
|
44
|
+
# and Bosnia and Herzegovina FIR
|
36
45
|
```
|
37
46
|
|
47
|
+
### Advanced usage
|
48
|
+
|
49
|
+
The `.notams` method can be customized by passing an optional hash of arguments.
|
50
|
+
|
51
|
+
The `:objects => true` option will cause the `.notams` method to return an array
|
52
|
+
of notam **objects** instead of strings. Thus each notam is parsed and
|
53
|
+
encapuslated in an instance of the `Notam` class and exposes a number of
|
54
|
+
**attributes**:
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
icao = "lqsa"
|
58
|
+
icao.notams(:objects => true) # => returns an array of notam objects
|
59
|
+
|
60
|
+
notam = icao.notams.first # => returns the first notam as an object
|
61
|
+
|
62
|
+
# Notam object attributes
|
63
|
+
|
64
|
+
notam.raw # => returns the raw (unprocessed) notam as a string
|
65
|
+
notam.icao # => returns the icao code of the airport or area, covered by the notam;
|
66
|
+
# useful when iterating over multiple notams, covering a collection of airports or areas
|
67
|
+
notam.message # => returns the actual information message of the notam as a string
|
68
|
+
```
|
69
|
+
|
70
|
+
### Example Ruby on Rails implementation
|
71
|
+
|
72
|
+
Here's a possible scenario of using this gem in a Ruby on Rails application.
|
73
|
+
Verbosity is kept on purpose for clarity.
|
74
|
+
|
75
|
+
**In your controller:**
|
76
|
+
```ruby
|
77
|
+
def action
|
78
|
+
|
79
|
+
# We define the airpots and/or areas that we're interested in.
|
80
|
+
# In this case this is Sarajevo Airport and the entire Bosnia & Herzegovina FIR
|
81
|
+
|
82
|
+
icao = "lqsa, lqsb"
|
83
|
+
|
84
|
+
# Now we want to pull all the latest notams for both these areas.
|
85
|
+
# We also want to pull them as objects, so that we can process their attributes
|
86
|
+
# separately in our views. We're assigning the result to the @notams instance
|
87
|
+
# variable which we will use in our views
|
88
|
+
|
89
|
+
@notams = icao.notams(:objects => true)
|
90
|
+
|
91
|
+
end
|
92
|
+
```
|
93
|
+
|
94
|
+
**In your view (HAML is used for clarity):**
|
95
|
+
|
96
|
+
```haml
|
97
|
+
// We could play with the attributes individually if we need to:
|
98
|
+
- for notam in @notams
|
99
|
+
%li
|
100
|
+
= notam.icao
|
101
|
+
= notam.message
|
102
|
+
|
103
|
+
// Or we could just loop through the raw notams:
|
104
|
+
- for notam in @notams
|
105
|
+
%li= notam.raw
|
106
|
+
```
|
107
|
+
|
108
|
+
## Changelog
|
109
|
+
|
110
|
+
### v. 0.1 28 July 2012
|
111
|
+
|
112
|
+
* added optional arguments customization to the `.notams` method (see [Advanced Usage](#advanced-usage))
|
113
|
+
* code refactored into classes for flexibility
|
114
|
+
|
115
|
+
|
38
116
|
## Contributing
|
39
117
|
|
40
118
|
1. Fork it
|
41
119
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
42
120
|
3. Commit your changes (`git commit -am 'Added some feature'`)
|
43
|
-
4.
|
44
|
-
5.
|
121
|
+
4. Make sure all tests are passing
|
122
|
+
5. Push to the branch (`git push origin my-new-feature`)
|
123
|
+
6. Create new Pull Request
|
data/lib/notams.rb
CHANGED
@@ -1,25 +1,82 @@
|
|
1
1
|
require "notams/version"
|
2
|
-
require 'nokogiri'
|
3
|
-
require 'open-uri'
|
4
|
-
|
5
2
|
|
6
3
|
class String
|
7
|
-
def notams
|
8
|
-
Notams.notams(self)
|
4
|
+
def notams(args={})
|
5
|
+
Notams.notams(self, args)
|
9
6
|
end
|
10
7
|
end
|
11
8
|
|
12
9
|
module Notams
|
13
|
-
def self.notams(icao)
|
14
|
-
|
15
|
-
|
16
|
-
|
10
|
+
def self.notams(icao, args)
|
11
|
+
NotamFetcher.new(icao, args).fetch
|
12
|
+
end
|
13
|
+
|
14
|
+
class NotamFetcher
|
15
|
+
require 'nokogiri'
|
16
|
+
require 'open-uri'
|
17
|
+
|
18
|
+
attr_accessor :icao, :obj_list, :notams, :string_notams
|
19
|
+
|
20
|
+
def initialize(icao, args = nil)
|
21
|
+
@icao = icao
|
22
|
+
process_arguments(args) if args.class == Hash
|
23
|
+
@notams = []; @string_notams = []
|
24
|
+
notams_object_list
|
25
|
+
notams_string_list
|
26
|
+
end
|
27
|
+
|
28
|
+
def raw_list
|
29
|
+
Nokogiri::HTML(open("https://pilotweb.nas.faa.gov/PilotWeb/notamRetrievalByICAOAction.do?method=displayByICAOs&reportType=RAW&formatType=DOMESTIC&retrieveLocId=#{@icao}&actionType=notamRetrievalByICAOs"))
|
30
|
+
end
|
31
|
+
|
32
|
+
def fetch
|
33
|
+
@obj_list == true ? @notams : @string_notams
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def notams_string_list
|
39
|
+
@notams.each {|n| @string_notams << n.to_s}
|
40
|
+
end
|
41
|
+
|
42
|
+
def notams_object_list
|
43
|
+
raw_list.css("pre").each {|n| @notams << Notam.new(n.text)}
|
44
|
+
end
|
45
|
+
|
46
|
+
def process_arguments(args)
|
47
|
+
args[:objects] == true ? @obj_list = true : @obj_list = false
|
48
|
+
end
|
49
|
+
|
17
50
|
end
|
18
51
|
|
19
|
-
|
52
|
+
class Notam
|
53
|
+
|
54
|
+
attr_accessor :raw, :message, :icao
|
55
|
+
|
56
|
+
def initialize(text)
|
57
|
+
@raw = text
|
58
|
+
@message = get_message
|
59
|
+
@icao = get_icao
|
60
|
+
end
|
61
|
+
|
62
|
+
def to_s
|
63
|
+
@raw
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def get_message
|
69
|
+
starts = @raw.index('E)') + 3
|
70
|
+
@raw.index('F)') ? ends = @raw.index('F)') : ends = @raw.length
|
71
|
+
@raw[starts..ends]
|
72
|
+
end
|
73
|
+
|
74
|
+
def get_icao
|
75
|
+
starts = @raw.index('A)') + 3
|
76
|
+
ends = @raw.index('B)') - 2
|
77
|
+
@raw[starts..ends]
|
78
|
+
end
|
20
79
|
|
21
|
-
def self.get_raw_page(icao)
|
22
|
-
Nokogiri::HTML(open("https://pilotweb.nas.faa.gov/PilotWeb/notamRetrievalByICAOAction.do?method=displayByICAOs&reportType=RAW&formatType=DOMESTIC&retrieveLocId=#{icao}&actionType=notamRetrievalByICAOs"))
|
23
80
|
end
|
24
81
|
|
25
82
|
end
|
data/lib/notams/version.rb
CHANGED
data/notams.gemspec
CHANGED
data/spec/notams_spec.rb
CHANGED
@@ -36,15 +36,46 @@ describe String do
|
|
36
36
|
"lqsa".notams.length.should_not eq("lqsa,lqsb".notams.length)
|
37
37
|
end
|
38
38
|
|
39
|
+
it "should process params" do
|
40
|
+
"lqsa".notams(:objects => false).should eq("lqsa".notams)
|
41
|
+
"lqsa".notams(:objects => false).should_not eq("lqsa".notams(:objects => true))
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should return objects when argument is set" do
|
45
|
+
icao = "lqsa"
|
46
|
+
icao.notams(:objects => true).class.should eq(Array)
|
47
|
+
Notams::NotamFetcher.new(icao, :objects => true).obj_list.should eq(true)
|
48
|
+
Notams::NotamFetcher.new(icao, :objects => true).notams.should_not eq(Notams::NotamFetcher.new(icao, :objects => true).string_notams)
|
49
|
+
icao.notams(:objects => true).first.class.should_not eq(String)
|
50
|
+
icao.notams(:objects => true).first.class.should eq(Notams::Notam)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should properly return the notam object message" do
|
54
|
+
icao = "lqsa"
|
55
|
+
Notams::NotamFetcher.new(icao, :objects => true).fetch.first.message.should eq(icao.notams(:objects => true).first.message)
|
56
|
+
icao.notams(:objects => true).first.message.class.should eq(String)
|
57
|
+
# "lqsb".notams(:objects => true).first.message.should eq("moo")
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should properly return the notam object icao" do
|
61
|
+
icao = "lqsa"
|
62
|
+
Notams::NotamFetcher.new(icao, :objects => true).fetch.first.icao.should eq(icao.notams(:objects => true).first.icao)
|
63
|
+
icao.notams(:objects => true).first.icao.class.should eq(String)
|
64
|
+
icao.notams(:objects => true).first.icao.should eq("LQSA")
|
65
|
+
icao.notams(:objects => true).first.icao.should eq(icao.upcase)
|
66
|
+
"lqsb".notams(:objects => true).first.icao.should eq("LQSB")
|
67
|
+
end
|
68
|
+
|
69
|
+
|
39
70
|
end
|
40
71
|
|
41
|
-
describe Notams do
|
72
|
+
describe Notams::NotamFetcher do
|
42
73
|
|
43
|
-
describe "
|
74
|
+
describe "raw_list" do
|
44
75
|
it "should execute open uri request via Nokogiri" do
|
45
76
|
icao = "lqsa"
|
46
|
-
Notams.
|
47
|
-
Notams.
|
77
|
+
Notams::NotamFetcher.new(icao).raw_list.class.should eq(Nokogiri::HTML::Document)
|
78
|
+
Notams::NotamFetcher.new(icao).raw_list.css("title").text.should eq("PilotWeb: Results Page ")
|
48
79
|
end
|
49
80
|
end
|
50
81
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: notams
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.1'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-07-
|
12
|
+
date: 2012-07-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -96,17 +96,17 @@ dependencies:
|
|
96
96
|
requirement: !ruby/object:Gem::Requirement
|
97
97
|
none: false
|
98
98
|
requirements:
|
99
|
-
- -
|
99
|
+
- - ~>
|
100
100
|
- !ruby/object:Gem::Version
|
101
|
-
version:
|
101
|
+
version: 1.5.5
|
102
102
|
type: :runtime
|
103
103
|
prerelease: false
|
104
104
|
version_requirements: !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
|
-
- -
|
107
|
+
- - ~>
|
108
108
|
- !ruby/object:Gem::Version
|
109
|
-
version:
|
109
|
+
version: 1.5.5
|
110
110
|
description: Retrieves the currently active NOTAMs for an airport or a region. Supports
|
111
111
|
multiple airports/regions in one request. Pulls data from FAA website.
|
112
112
|
email:
|