Class: Rome2rio::Segment

Inherits:
Object
  • Object
show all
Defined in:
lib/rome2rio/response/segment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json) ⇒ Segment

Returns a new instance of Segment.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rome2rio/response/segment.rb', line 5

def initialize(json)
  # Possible kinds: walk, car, train, bus, ferry, flight
  @kind = json["kind"]
  @isMajor = json["isMajor"] == 1
  @distance = json["distance"]
  @duration = json["duration"]
  @indicativePrice = IndicativePrice.new(json["indicativePrice"])

  if @kind != "flight" then
    @isImperial = json["isImperial"] == 1
    @sName = json["sName"]
    @sPos = Position.parse(json["sPos"])
    @tName = json["tName"]
    @tPos = Position.parse(json["tPos"])
    @path = json["path"]
  else
    @sCode = json["sCode"]
    @tCode = json["tCode"]
    @itineraries = []
    json["itineraries"].each { |itinerary| @itineraries << FlightItinerary.new(itinerary) }
  end

  if [ "train", "bus", "ferry" ].include?(@kind) then
    @subkind = json["subkind"]
    @itineraries = []
    json["itineraries"].each { |itinerary| @itineraries << TransitItinerary.new(itinerary) }
  end
end

Instance Attribute Details

#distanceObject (readonly)

Returns the value of attribute distance.



3
4
5
# File 'lib/rome2rio/response/segment.rb', line 3

def distance
  @distance
end

#durationObject (readonly)

Returns the value of attribute duration.



3
4
5
# File 'lib/rome2rio/response/segment.rb', line 3

def duration
  @duration
end

#indicativePriceObject (readonly)

Returns the value of attribute indicativePrice.



3
4
5
# File 'lib/rome2rio/response/segment.rb', line 3

def indicativePrice
  @indicativePrice
end

#isImperialObject (readonly)

Returns the value of attribute isImperial.



3
4
5
# File 'lib/rome2rio/response/segment.rb', line 3

def isImperial
  @isImperial
end

#isMajorObject (readonly)

Returns the value of attribute isMajor.



3
4
5
# File 'lib/rome2rio/response/segment.rb', line 3

def isMajor
  @isMajor
end

#itinerariesObject (readonly)

Returns the value of attribute itineraries.



3
4
5
# File 'lib/rome2rio/response/segment.rb', line 3

def itineraries
  @itineraries
end

#kindObject (readonly)

Returns the value of attribute kind.



3
4
5
# File 'lib/rome2rio/response/segment.rb', line 3

def kind
  @kind
end

#pathObject (readonly)

Returns the value of attribute path.



3
4
5
# File 'lib/rome2rio/response/segment.rb', line 3

def path
  @path
end

#sCodeObject (readonly)

Returns the value of attribute sCode.



3
4
5
# File 'lib/rome2rio/response/segment.rb', line 3

def sCode
  @sCode
end

#sNameObject (readonly)

Returns the value of attribute sName.



3
4
5
# File 'lib/rome2rio/response/segment.rb', line 3

def sName
  @sName
end

#sPosObject (readonly)

Returns the value of attribute sPos.



3
4
5
# File 'lib/rome2rio/response/segment.rb', line 3

def sPos
  @sPos
end

#subkindObject (readonly)

Returns the value of attribute subkind.



3
4
5
# File 'lib/rome2rio/response/segment.rb', line 3

def subkind
  @subkind
end

#tCodeObject (readonly)

Returns the value of attribute tCode.



3
4
5
# File 'lib/rome2rio/response/segment.rb', line 3

def tCode
  @tCode
end

#tNameObject (readonly)

Returns the value of attribute tName.



3
4
5
# File 'lib/rome2rio/response/segment.rb', line 3

def tName
  @tName
end

#tPosObject (readonly)

Returns the value of attribute tPos.



3
4
5
# File 'lib/rome2rio/response/segment.rb', line 3

def tPos
  @tPos
end