Class: KrkTimetables::Stop
- Inherits:
-
Object
- Object
- KrkTimetables::Stop
- Defined in:
- lib/krk-timetables_stop.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name, url) ⇒ Stop
constructor
A new instance of Stop.
- #lines ⇒ Object
Constructor Details
#initialize(name, url) ⇒ Stop
Returns a new instance of Stop.
5 6 7 |
# File 'lib/krk-timetables_stop.rb', line 5 def initialize(name, url) @name, @lines, @url = name, [], url end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/krk-timetables_stop.rb', line 3 def name @name end |
Class Method Details
.find_by_name(name) ⇒ Object
9 10 11 |
# File 'lib/krk-timetables_stop.rb', line 9 def self.find_by_name(name) KrkTimetables.stops.select { |stop| stop.name == name }.first end |
Instance Method Details
#lines ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/krk-timetables_stop.rb', line 13 def lines return @lines unless @lines.empty? doc = Nokogiri::HTML(open(KrkTimetables::URL_PREFIX + @url)) doc.css("table li a").each do |line_link| line_link_data = line_link.content.split(" - > ") next unless line_link_data.size == 2 number = line_link_data.first.to_i destination = line_link_data.last url = line_link.attributes["href"].value @lines << KrkTimetables::Line.new(number, destination, url) end @lines end |