Class: PLA::Movements
- Inherits:
-
Object
- Object
- PLA::Movements
- Defined in:
- lib/pla/movements.rb
Direct Known Subclasses
Class Attribute Summary collapse
-
.url ⇒ Object
Returns the value of attribute url.
Instance Attribute Summary collapse
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#records ⇒ Object
readonly
Returns the value of attribute records.
Class Method Summary collapse
Instance Method Summary collapse
- #get_ships_data ⇒ Object
-
#initialize ⇒ Movements
constructor
A new instance of Movements.
- #set_headers ⇒ Object
- #set_records ⇒ Object
Constructor Details
#initialize ⇒ Movements
Returns a new instance of Movements.
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/pla/movements.rb', line 18 def initialize @url = self.class.url @root = 'div.newsMainArea table tr td table tr' # It gets worse @records = [] @ships = get_ships_data set_headers set_records @records end |
Class Attribute Details
.url ⇒ Object
Returns the value of attribute url.
10 11 12 |
# File 'lib/pla/movements.rb', line 10 def url @url end |
Instance Attribute Details
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
16 17 18 |
# File 'lib/pla/movements.rb', line 16 def headers @headers end |
#records ⇒ Object (readonly)
Returns the value of attribute records.
16 17 18 |
# File 'lib/pla/movements.rb', line 16 def records @records end |
Class Method Details
.set_url(u) ⇒ Object
11 12 13 |
# File 'lib/pla/movements.rb', line 11 def set_url u @url = u end |
Instance Method Details
#get_ships_data ⇒ Object
31 32 33 |
# File 'lib/pla/movements.rb', line 31 def get_ships_data Nokogiri::HTML(open(@url)).css(@root) end |
#set_headers ⇒ Object
35 36 37 38 |
# File 'lib/pla/movements.rb', line 35 def set_headers @headers = normalize_and_map(@ships.first.css('th')) @headers[-1] = 'notes' # pla returns this as empty. We infer it means notes, though usually it says 'Pilot required' end |
#set_records ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/pla/movements.rb', line 40 def set_records @ships[1..-1].each do |t| record = {} fields = normalize_and_map(t.css('td')) fields.each_with_index do |f,i| record[ @headers[i].to_sym ] = f end movement = PLA::Movement.new(record) @records << movement.to_h end end |