Class: OsmImport::Target::PgBase::TargetEntry

Inherits:
Object
  • Object
show all
Defined in:
lib/osm_import/target/pg_base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target, conn, table) ⇒ TargetEntry

Returns a new instance of TargetEntry.



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/osm_import/target/pg_base.rb', line 50

def initialize(target, conn, table)
  @target = target
  @conn = conn
  @table = table

  @type_mapping = table.type_mapper.expression
  @types_mapping = table.type_mapper.expression_multi
  @name_mapping = "NULLIF(COALESCE(src.tags->'name:ru', src.tags->'name', src.tags->'int_name'), '')"

  @fields = table.type_mapper.fields.merge :id => 'INT8 PRIMARY KEY',  :name => 'VARCHAR(255)', :tags => 'HSTORE', :osm_type => 'VARCHAR(10)'
  @assigns = table.type_mapper.assigns.merge :id => osm_id_expr, :name => name_mapping, :tags => 'src.tags', :osm_type => osm_type_expr
  @conditions = table.type_mapper.conditions

  table.mappers.each do |key, mapper|
    @fields.merge! mapper.fields
    @assigns.merge! mapper.assigns
  end
end

Instance Attribute Details

#assignsObject (readonly)

Returns the value of attribute assigns.



48
49
50
# File 'lib/osm_import/target/pg_base.rb', line 48

def assigns
  @assigns
end

#conditionsObject (readonly)

Returns the value of attribute conditions.



48
49
50
# File 'lib/osm_import/target/pg_base.rb', line 48

def conditions
  @conditions
end

#connObject (readonly)

Returns the value of attribute conn.



48
49
50
# File 'lib/osm_import/target/pg_base.rb', line 48

def conn
  @conn
end

#fieldsObject (readonly)

Returns the value of attribute fields.



48
49
50
# File 'lib/osm_import/target/pg_base.rb', line 48

def fields
  @fields
end

#name_mappingObject (readonly)

Returns the value of attribute name_mapping.



48
49
50
# File 'lib/osm_import/target/pg_base.rb', line 48

def name_mapping
  @name_mapping
end

#tableObject (readonly)

Returns the value of attribute table.



48
49
50
# File 'lib/osm_import/target/pg_base.rb', line 48

def table
  @table
end

#targetObject (readonly)

Returns the value of attribute target.



48
49
50
# File 'lib/osm_import/target/pg_base.rb', line 48

def target
  @target
end

#type_mappingObject (readonly)

Returns the value of attribute type_mapping.



48
49
50
# File 'lib/osm_import/target/pg_base.rb', line 48

def type_mapping
  @type_mapping
end

#types_mappingObject (readonly)

Returns the value of attribute types_mapping.



48
49
50
# File 'lib/osm_import/target/pg_base.rb', line 48

def types_mapping
  @types_mapping
end

Instance Method Details

#geometry_exprObject



77
78
79
80
81
82
83
# File 'lib/osm_import/target/pg_base.rb', line 77

def geometry_expr
  if table.type =~ /^multi/
    'ST_Multi(way)'
  else
    'way'
  end
end

#nameObject



85
86
87
# File 'lib/osm_import/target/pg_base.rb', line 85

def name
  "#{target.new_prefix}#{table.name}"
end

#osm_id_exprObject



69
70
71
# File 'lib/osm_import/target/pg_base.rb', line 69

def osm_id_expr
  "ABS(src.osm_id)"
end

#osm_type_expr(t = table.type) ⇒ Object



73
74
75
# File 'lib/osm_import/target/pg_base.rb', line 73

def osm_type_expr(t = table.type)
  "CASE WHEN src.osm_id < 0 THEN 'relation' ELSE '#{if t.to_s == 'point' then 'node' else 'way' end}' END"
end