Class: Amtrak::TrainFetcher

Inherits:
Object
  • Object
show all
Defined in:
lib/amtrak/train_fetcher.rb

Overview

Service for getting train time HTML page from the Amtrak website

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(from, to, date: nil) ⇒ TrainFetcher

Returns a new instance of TrainFetcher.



14
15
16
17
18
# File 'lib/amtrak/train_fetcher.rb', line 14

def initialize(from, to, date: nil)
  @from = from
  @to = to
  @date = date || Date.today
end

Instance Attribute Details

#dateObject (readonly)

Returns the value of attribute date.



12
13
14
# File 'lib/amtrak/train_fetcher.rb', line 12

def date
  @date
end

#fromObject (readonly)

Returns the value of attribute from.



12
13
14
# File 'lib/amtrak/train_fetcher.rb', line 12

def from
  @from
end

#toObject (readonly)

Returns the value of attribute to.



12
13
14
# File 'lib/amtrak/train_fetcher.rb', line 12

def to
  @to
end

Class Method Details

.get(*args) ⇒ Object



8
9
10
# File 'lib/amtrak/train_fetcher.rb', line 8

def self.get(*args)
  new(*args).get
end

Instance Method Details

#check_releaseObject



20
21
22
# File 'lib/amtrak/train_fetcher.rb', line 20

def check_release
  first_page.release == '6.25.02a'
end

#getObject



24
25
26
# File 'lib/amtrak/train_fetcher.rb', line 24

def get
  JSON.parse(response.body)
end