Class: SimpleGeo::Record
- Inherits:
-
Object
- Object
- SimpleGeo::Record
- Defined in:
- lib/simple_geo/record.rb
Instance Attribute Summary collapse
-
#created ⇒ Object
Returns the value of attribute created.
-
#id ⇒ Object
Returns the value of attribute id.
-
#lat ⇒ Object
Returns the value of attribute lat.
-
#layer ⇒ Object
Returns the value of attribute layer.
-
#lon ⇒ Object
Returns the value of attribute lon.
-
#properties ⇒ Object
Returns the value of attribute properties.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(options = {}) ⇒ Record
constructor
A new instance of Record.
- #to_hash ⇒ Object
- #to_json(*a) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Record
Returns a new instance of Record.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/simple_geo/record.rb', line 5 def initialize(={}) = { :created => Time.now, :type => 'object', :properties => {} }.merge() @id = [:id] @layer = [:layer] @type = [:type] @lat = [:lat] @lon = [:lon] @created = [:created] @properties = [:properties] end |
Instance Attribute Details
#created ⇒ Object
Returns the value of attribute created.
3 4 5 |
# File 'lib/simple_geo/record.rb', line 3 def created @created end |
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/simple_geo/record.rb', line 3 def id @id end |
#lat ⇒ Object
Returns the value of attribute lat.
3 4 5 |
# File 'lib/simple_geo/record.rb', line 3 def lat @lat end |
#layer ⇒ Object
Returns the value of attribute layer.
3 4 5 |
# File 'lib/simple_geo/record.rb', line 3 def layer @layer end |
#lon ⇒ Object
Returns the value of attribute lon.
3 4 5 |
# File 'lib/simple_geo/record.rb', line 3 def lon @lon end |
#properties ⇒ Object
Returns the value of attribute properties.
3 4 5 |
# File 'lib/simple_geo/record.rb', line 3 def properties @properties end |
#type ⇒ Object
Returns the value of attribute type.
3 4 5 |
# File 'lib/simple_geo/record.rb', line 3 def type @type end |
Class Method Details
.parse_geojson_hash(json_hash) ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/simple_geo/record.rb', line 44 def self.parse_geojson_hash(json_hash) Record.new( :id => json_hash['id'], :type => json_hash['properties'].delete('type'), :lat => json_hash['geometry']['coordinates'][1], :lon => json_hash['geometry']['coordinates'][0], :created => Time.at(json_hash['created']), :properties => HashUtils.recursively_symbolize_keys(json_hash['properties']) ) end |
Instance Method Details
#==(other) ⇒ Object
40 41 42 |
# File 'lib/simple_geo/record.rb', line 40 def ==(other) other.class == self.class && self.to_hash == other.to_hash end |
#to_hash ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/simple_geo/record.rb', line 21 def to_hash { :type => 'Feature', :id => id, :created => created.to_i, :geometry => { :type => 'Point', :coordinates => [ lon, lat ] }, :properties => properties.merge({ :type => type }) } end |
#to_json(*a) ⇒ Object
36 37 38 |
# File 'lib/simple_geo/record.rb', line 36 def to_json(*a) self.to_hash.to_json(*a) end |