Module: GeoVector::Parser::ClassMethods

Included in:
GeoVector::Parser
Defined in:
lib/geo_vectors/vector_parser.rb

Instance Method Summary collapse

Instance Method Details

#create_vector(*args) ⇒ Object



4
5
6
7
# File 'lib/geo_vectors/vector_parser.rb', line 4

def create_vector *args
  first_arg = args[0]             
  first_arg.any_kind_of?(GeoVector, GeoVectors) ? first_arg : parse_vector(*args)
end

#parse_bearing_vector(*args) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/geo_vectors/vector_parser.rb', line 35

def parse_bearing_vector *args 
  begin
    BearingVector.new *args
  rescue
    nil
  end
end

#parse_direction_vector(*args) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/geo_vectors/vector_parser.rb', line 43

def parse_direction_vector *args 
  begin
    DirectionVector.new *args
  rescue
    nil
  end
end

#parse_multiple_vector(*args) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/geo_vectors/vector_parser.rb', line 19

def parse_multiple_vector *args 
  begin
    GeoVectors.new *args
  rescue
    nil
  end
end

#parse_point_vector(*args) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/geo_vectors/vector_parser.rb', line 27

def parse_point_vector *args 
  begin
    PointVector.new *args
  rescue
    nil
  end
end

#parse_vector(*args) ⇒ Object

Raises:

  • (ArgumentError)


9
10
11
12
13
# File 'lib/geo_vectors/vector_parser.rb', line 9

def parse_vector *args
  res = [:point, :bearing, :direction, :multiple].map {|type| send parser(type), *args }.compact.first
  raise ArgumentError, "No GeoVector could be created from arguments: #{args}" if !res
  res
end

#parser(type) ⇒ Object



15
16
17
# File 'lib/geo_vectors/vector_parser.rb', line 15

def parser type
  "parse_#{type}_vector"
end