Class: Terragona::Generic::FromHash

Inherits:
Object
  • Object
show all
Defined in:
lib/terragona/generic.rb

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ FromHash

Returns a new instance of FromHash.



42
43
44
45
46
47
48
49
# File 'lib/terragona/generic.rb', line 42

def initialize(args = {})
  # @hash should be actually an array of hashes
  @hash = args[:hash]

  return unless @hash

  @id_counter = 0
end

Instance Method Details

#search(options = {}) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/terragona/generic.rb', line 50

def search(options = {})
  @id_counter +=1

  name = options[:name]

  points = []

  if name == :generic
    children = []

    @hash.each {|p|
      points.push({:x => p[:x], :y => p[:y]})
      children.push({:name => p[:name]})
    }

    children.uniq!

    children_places = (children.count > 1 )? children : []
  else
    @hash.select{|row| row[:name] == name}.each {|p| points.push({:x => p[:x], :y => p[:y]})}
    children_places = []
  end

  {:children_places=>children_places, :points => points, :place_name=> name, :place_id=>@id_counter}
end