Class: GeojsonDiff::PropertyDiff
- Inherits:
-
Object
- Object
- GeojsonDiff::PropertyDiff
- Defined in:
- lib/geojson-diff/property-diff.rb
Instance Method Summary collapse
-
#added ⇒ Object
Returns an array of all keys added to the resulting geometry.
-
#added?(key) ⇒ Boolean
Checks if the given key has been added to the resulting geometry.
-
#changed ⇒ Object
Returns an array of all keys modified in the resulting geometry.
-
#changed?(key) ⇒ Boolean
Checks if the given key has been modified in the resulting geometry.
-
#diff ⇒ Object
(also: #properties)
Returns a hash of the diffed properties, including metadata.
-
#initialize(before, after) ⇒ PropertyDiff
constructor
Creates a new PropertyDiff instance.
- #inspect ⇒ Object
-
#removed ⇒ Object
Returns an array of all keys removed from the resulting geometry.
-
#removed?(key) ⇒ Boolean
Checks if the given key has been removed from the resulting geometry.
-
#to_json ⇒ Object
Returns the JSON representation of the diffed properties, including metadata.
- #to_s ⇒ Object
Constructor Details
#initialize(before, after) ⇒ PropertyDiff
Creates a new PropertyDiff instance
before - the property element of the starting geometry (as parsed JSON) after - the property element of the resulting geometry (as parsed JSON)
returns the PropertyDiff instance
10 11 12 13 14 15 |
# File 'lib/geojson-diff/property-diff.rb', line 10 def initialize(before,after) @before = before @after = after @meta = { :added => [], :removed => [], :changed => [] } diff end |
Instance Method Details
#added ⇒ Object
Returns an array of all keys added to the resulting geometry
27 28 29 |
# File 'lib/geojson-diff/property-diff.rb', line 27 def added @meta[:added] end |
#added?(key) ⇒ Boolean
Checks if the given key has been added to the resulting geometry
key - string the JSON property key to check
Returns bool true if added, otherwise false
22 23 24 |
# File 'lib/geojson-diff/property-diff.rb', line 22 def added?(key) !@before.key?(key) && @after.key?(key) end |
#changed ⇒ Object
Returns an array of all keys modified in the resulting geometry
55 56 57 |
# File 'lib/geojson-diff/property-diff.rb', line 55 def changed @meta[:changed] end |
#changed?(key) ⇒ Boolean
Checks if the given key has been modified in the resulting geometry
key - string the JSON property key to check
Returns bool true if modified, otherwise false
50 51 52 |
# File 'lib/geojson-diff/property-diff.rb', line 50 def changed?(key) !added?(key) && !removed?(key) && @before[key] != @after[key] end |
#diff ⇒ Object Also known as: properties
Returns a hash of the diffed properties, including metadata
73 74 75 76 77 78 79 |
# File 'lib/geojson-diff/property-diff.rb', line 73 def diff @diff ||= begin properties = {} @before.merge(@after).each { |key,value| properties.merge! diffed_property(key) } properties.merge({ GeojsonDiff::META_KEY => @meta }) end end |
#inspect ⇒ Object
68 69 70 |
# File 'lib/geojson-diff/property-diff.rb', line 68 def inspect "#<GeojsonDiff::PropertyDiff added=#{added.to_s} removed=#{removed.to_s} changed=#{changed.to_s}>" end |
#removed ⇒ Object
Returns an array of all keys removed from the resulting geometry
41 42 43 |
# File 'lib/geojson-diff/property-diff.rb', line 41 def removed @meta[:removed] end |
#removed?(key) ⇒ Boolean
Checks if the given key has been removed from the resulting geometry
key - string the JSON property key to check
Returns bool true if removed, otherwise false
36 37 38 |
# File 'lib/geojson-diff/property-diff.rb', line 36 def removed?(key) @before.key?(key) && !@after.key?(key) end |
#to_json ⇒ Object
Returns the JSON representation of the diffed properties, including metadata
60 61 62 |
# File 'lib/geojson-diff/property-diff.rb', line 60 def to_json diff.to_json end |
#to_s ⇒ Object
64 65 66 |
# File 'lib/geojson-diff/property-diff.rb', line 64 def to_s diff.to_s end |