Class: Terraformer::Primitive
- Inherits:
-
Object
- Object
- Terraformer::Primitive
- Defined in:
- lib/terraformer.rb
Overview
abstract base class for terraformer objects. implements bbox
and envelope
.
Direct Known Subclasses
Instance Method Summary collapse
-
#bbox(type = :bbox) ⇒ Object
returns a bounding box array of values, with minimum axis values followed by maximum axis values.
-
#envelope ⇒ Object
returns a bounding envelope as a
Hash
of the geometry. -
#initialize(*args) {|arg| ... } ⇒ Primitive
constructor
handles basic JSON parsing for terraformer object constructors.
-
#to_json(*args) ⇒ Object
base
to_json
implementation for all terraformer objects. -
#type ⇒ Object
terraformer object type as a
String
.
Constructor Details
#initialize(*args) {|arg| ... } ⇒ Primitive
handles basic JSON parsing for terraformer object constructors.
74 75 76 77 78 79 80 81 |
# File 'lib/terraformer.rb', line 74 def initialize *args arg = args[0] arg = JSON.parse(arg) if String === arg raise ArgumentError.new "invalid argument(s): #{args}" unless Hash === arg raise ArgumentError.new "invalid type: #{arg['type']}" unless arg['type'] == self.type yield arg if block_given? end |
Instance Method Details
#bbox(type = :bbox) ⇒ Object
returns a bounding box array of values, with minimum axis values followed by maximum axis values.
99 100 101 |
# File 'lib/terraformer.rb', line 99 def bbox type = :bbox Bounds.bounds self.respond_to?(:geometry) ? self.geometry : self, type end |
#envelope ⇒ Object
returns a bounding envelope as a Hash
of the geometry. the envelope has keys for coordinates x
and y
, and dimensions w
and h
.
92 93 94 |
# File 'lib/terraformer.rb', line 92 def envelope Bounds.envelope self.respond_to?(:geometry) ? self.geometry : self end |
#to_json(*args) ⇒ Object
base to_json
implementation for all terraformer objects.
105 106 107 108 109 |
# File 'lib/terraformer.rb', line 105 def to_json *args h = self.to_hash *args args.pop if Hash === args.last h.to_json *args end |
#type ⇒ Object
terraformer object type as a String
.
85 86 87 |
# File 'lib/terraformer.rb', line 85 def type self.class.to_s.sub 'Terraformer::', '' end |