Class: MapPLZ
- Inherits:
-
Object
- Object
- MapPLZ
- Defined in:
- lib/mapplz.rb
Overview
MapPLZ datastore
Instance Method Summary collapse
-
#<<(user_geo) ⇒ Object
aliases for add.
- #add(user_geo) ⇒ Object
- #code(mapplz_code) ⇒ Object
- #count(where_clause = nil, add_on = nil) ⇒ Object
-
#initialize ⇒ MapPLZ
constructor
A new instance of MapPLZ.
- #length(where_clause = nil, add_on = nil) ⇒ Object
- #push(user_geo) ⇒ Object
- #query(where_clause, add_on) ⇒ Object
-
#size(where_clause = nil, add_on = nil) ⇒ Object
aliases for count.
- #to_geojson ⇒ Object
Constructor Details
#initialize ⇒ MapPLZ
Returns a new instance of MapPLZ.
8 9 10 11 12 |
# File 'lib/mapplz.rb', line 8 def initialize @db_type = 'array' @parser = SqlParser.new @my_array = [] end |
Instance Method Details
#<<(user_geo) ⇒ Object
aliases for add
77 78 79 |
# File 'lib/mapplz.rb', line 77 def <<(user_geo) add(user_geo) end |
#add(user_geo) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/mapplz.rb', line 14 def add(user_geo) geo_objects = standardize_geo(user_geo) @my_array += geo_objects if geo_objects.length == 1 geo_objects[0] else geo_objects end end |
#code(mapplz_code) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/mapplz.rb', line 51 def code(mapplz_code) @code_lines = mapplz_code.gsub("\r", '').split("\n") @code_level = 'toplevel' @button_layers = [] @code_button = 0 @code_layers = [] @code_label = '' @code_color = nil code_line(0) @code_layers end |
#count(where_clause = nil, add_on = nil) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/mapplz.rb', line 25 def count(where_clause = nil, add_on = nil) results = query(where_clause, add_on) if @db_type == 'array' results.length else results.count end end |
#length(where_clause = nil, add_on = nil) ⇒ Object
90 91 92 |
# File 'lib/mapplz.rb', line 90 def length(where_clause = nil, add_on = nil) count(where_clause, add_on) end |
#push(user_geo) ⇒ Object
81 82 83 |
# File 'lib/mapplz.rb', line 81 def push(user_geo) add(user_geo) end |
#query(where_clause, add_on) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/mapplz.rb', line 34 def query(where_clause, add_on) if where_clause.present? if @db_type == 'array' query_array(where_clause, add_on) else # @my_db.where(where_clause, add_on) end else # count all if @db_type == 'array' @my_array else # @my_db.all end end end |
#size(where_clause = nil, add_on = nil) ⇒ Object
aliases for count
86 87 88 |
# File 'lib/mapplz.rb', line 86 def size(where_clause = nil, add_on = nil) count(where_clause, add_on) end |
#to_geojson ⇒ Object
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/mapplz.rb', line 63 def to_geojson feature_list = [] if @db_type == 'array' @my_array.each do |feature| feature_list << as_geojson(feature) end end geojson = { type: 'FeatureCollection', features: feature_list } geojson.to_json end |