Class: Rome2rio::EncodedNumberPair

Inherits:
Object
  • Object
show all
Defined in:
lib/rome2rio/helper/encoded_number_pair.rb

Direct Known Subclasses

Offset, Position, Size

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(a = nil, b = nil) ⇒ EncodedNumberPair

Returns a new instance of EncodedNumberPair.



5
6
7
8
# File 'lib/rome2rio/helper/encoded_number_pair.rb', line 5

def initialize(a = nil, b = nil)
  @a = a
  @b = b
end

Instance Attribute Details

#aObject

Returns the value of attribute a.



3
4
5
# File 'lib/rome2rio/helper/encoded_number_pair.rb', line 3

def a
  @a
end

#bObject

Returns the value of attribute b.



3
4
5
# File 'lib/rome2rio/helper/encoded_number_pair.rb', line 3

def b
  @b
end

Class Method Details

.parse(str) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/rome2rio/helper/encoded_number_pair.rb', line 10

def self.parse(str)
  # failsafe for empty data
  return if not str or str.strip.length == 0

  ret = new
  str.scan(/([\d\.]+), ([\d\.]+)/).collect { |a, b| ret.a, ret.b = a, b }
  ret
end

Instance Method Details

#to_sObject



19
20
21
# File 'lib/rome2rio/helper/encoded_number_pair.rb', line 19

def to_s
  "#{a}, #{b}"
end